I want to use a text file to store my variables and values. How can I put the $var[0] into the respected variable name so i can:
<?php
echo $name;
echo $age;
echo $location;
echo $hobby;
?>
Here's my text format:
variables.txt
name##my name here
age##my age here
location##my city here
hobby##my hobby here
Here's the code.
<?php
$fh = fopen('variables.txt', 'r');
$data = fread($fh, filesize('variables.txt'));
fclose($fh);
$variables = explode("\n", $data);
#print_r($variables);
foreach ($variables as $variable) {
$var = explode("##", $variable);
echo $var[0] . " - " . $var[1];
}
?>