Example params.txt file extract:
height=100
width=50
width=50
PHP code snippet:
$param = array();
$paramsFile = fopen('params.txt','r');
while(!feof($paramsFile))
{
$buffer = fgets($paramsFile);
list($name,$value) = split('=',trim($buffer));
$param[$name] = $value;
}
fclose ($paramsFile);
$paramsFile = fopen('params.txt','r');
while(!feof($paramsFile))
{
$buffer = fgets($paramsFile);
list($name,$value) = split('=',trim($buffer));
$param[$name] = $value;
}
fclose ($paramsFile);
The array can then be referenced as:
echo $param['height'];
To use the tab character as the seperator instead of (=) equals, change the list line to:
list($name,$value) = split("\t",trim($buffer));
BlogEntry=Done
No comments:
Post a Comment