dimanche 27 décembre 2015

PHP is replacing ® with?

I'm trying to write a PHP script that verifies if the correct programs and libraries are correctly installed in the user's machine.

I generate a list of programs with the following line of code:

$installed_programs_list = shell_exec("wmic product get name,version /format:csv");

There is one line that should be

Intel® Trusted Connect Service Client,1.28.487.1

but my string comparison is failing because the $installed_programs_list variable has Intelr Trusted Connect Service Client,1.28.487.1.

I tried to play with the mb_detect_encondig and it does not seem to be able to detect that line. It shows ASCII for all other lines but nothing for Intel® line. I tried to force to UTF-8 but no luck. I don't know if I did it right.

I tried saving the output to a .csv file and reading back with fread() and the string shows Intel�

here is my code:

shell_exec("wmic product get name,version /format:csv > software_list.csv");
// get contents of a file into a string
$filename1 = "software_list.csv";
$handle = fopen($filename1, "rb");
$installed_programs_list = fread($handle, filesize($filename1));
fclose($handle);

echo $installed_programs_list;

Further below:

    //check if correct programs are installed
    foreach($installed_programs as $value){
        if(mb_strpos($installed_programs_list, trim($value)) === false){
            print_div("$value not installed.", "red");
            $test_passed = 0;   
        }else{
            print_div("$value installed.", "blue");
        }
    }

My goal is to create a series of automated tests for my company in PHP.

Thanks a lot for your help!

Aucun commentaire:

Enregistrer un commentaire