Can someone please tell me why this isn't working

i have a text file with variables saved in it like:

audB = 10.01
audS = 5.06
and so on

i’m trying to read the text file name the variable and give it a value using this
php

$handle = @fopen(“ex_rate.txt”, “r”);
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
list( $key, $value ) = explode( ‘|’, trim($buffer) );
$$key = $value; //Double $$ to set a var with the string name in $key
}
if (!feof($handle)) {
echo “Error: unexpected fgets() fail\n”;
}
fclose($handle);
}
echo $audB.$audS ;

php

it will not echo or print the variable… what am i doing wrong?

Don’t suppress error messages until you’re sure the script works. But that question is easy, there are no variables in the script called $audB or $audS. To php, its just another word in the text file. If you’re going to echo something, echo out $key and $value, see what’s being contained in them.

Sponsor our Newsletter | Privacy Policy | Terms of Service