I have this javascript template file filled with some macros like %macro_name% that I want to replace with some pre-defined values and I want to do this using str_replace function.
I'm using this code:
$options = array ("%frequencia%"=>"1",
"%idcliente%"=>"100");
$filename = "popup.js";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
while (list($key, $value) = each($options)) {
echo $key ."=". $value . "<br>"; //debug purposes only
$new = str_replace($key,$value,$contents);
}
This simply doesn't replace any of the two macros found in the file with the associated values in the array.
Can someone explain to me why?
It seems that the loop isn't retrieving the $key and $value elements...
Thanks.