I have a data file that my users upload with a section comprising of keys and values separated by tabs and line breaks:
key value
city London
year 1984
I import this into a script, then assign PHP variables with the names equal to the value:
$key = 'value';
$city = 'London';
$year = 1984;
This is used to populate templates that they've also uploaded.
This is my script that assigns to keys and values:
$userdata = explode("\n", $file);
foreach($userdata as &$line){
list($key, $value) = explode("\t", $line);
$$key = $value;}
I'm wondering if this is the best way to assign keys to values, if there are any security precautions I should take such as prevent certain key names, and if there would be a way to make a key equal to an array if the line has multiple tabs.
$props[$key] = $value.htaccessif you need to.