i have data file users upload section comprising of keys , values separated tabs , line breaks:
key value city london year 1984
i import script, assign php variables names equal value:
$key = 'value'; $city = 'london'; $year = 1984;
this used populate templates they've uploaded.
this script assigns keys , values:
$userdata = explode("\n", $file); foreach($userdata &$line){ list($key, $value) = explode("\t", $line); $$key = $value;}
i'm wondering if best way assign keys values, if there security precautions should take such prevent key names, , if there way make key equal array if line has multiple tabs.
i think should this:
<?php $filepointer = @fopen($file, 'r'); while($line = fgets($filepointer)){ $a = preg_split('/\b\s+\b/', $line); ${$a[0]} = $a[1]; } echo "key:$key; city:$city; year:$year;" ?>
Comments
Post a Comment