I am new to php and I am trying to make a script that reads a CSV file (file1.csv) and compares the words in the file with the words in the html file (file2.html) if the word in file2.html matches the key part in file1. csv, it should change the contents of file2.html with the value of the matching key.
what i have done so far:
$glossArray = array();
$file_handle = fopen("file1.csv", "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 10000,';');
$glossArray[$line_of_text[0]] = $line_of_text[1];
$counter++;
}
fclose($file_handle);
$file = file_get_contents("file2.html");
foreach($glossArray as $key => $value){
$results = str_replace($key," means ".$value ,$file);
}
echo $results;
I think my problem occurs when I try to iterate and change the values ββ.. because I only see the contents of file2.html without changes
any help would be appreciated
early
Nader
Ps I edited the old code with the new one after your valuable advice .. now it is like this .. but still does not work.
Update: changing foreach with:
$results = str_replace(array_keys($glossArray), "means ".array_values($glossArray), $file);
.. : , , "" .