The following script is not working as expected. It should take an associative array $data and search a string $contents, replacing all instances of $key with $val, but it does not do so.
I have a feeling that it has something to do with the array $data, but I can't see what. This script is ruining my weekend. could someone take a look and tell me what I am missing here?
<?php
$conf = "$news_config"; // config file name
$xml_file = trim($news_path . $GLOBALS[article]); // file to translate
// open the config file for read
$fp = fopen($conf, "r") or die("Error: Unable to Open Config File $conf");
// lock the file (shared)
flock($fp, 1);
while ($temp = fgetcsv($fp, 4096, "|")) {
$data[$temp[0]] = $temp[1];
}
flock($fp, 3); // release the lock
fclose($fp); // close the file
// open the XML file for read
$fp = fopen($xml_file, "r") or die("Error: Unable to Open XML File $xml_file");
flock($fp, 1);
$contents = fread($fp, filesize($xml_file));
flock($fp, 3); // release the lock
fclose($fp); // close the file
// replace every occurance of the name w/ the value in the file
foreach ($data as $key=>$val) {
$contents = str_replace($key, $val, $contents);
}
echo $contents;
?>