问题
I export a variable to a textarea via "var_export($schools,true)" so user can edit it. Then I want to 'update' the variable with the changes made. The updates is received via POST method.
I have some text that I want to become a variable. How can I do that?
What I do right now is that I edit the variable manually in .php file. I want to give an web interface to users do to the same. There won't be no security issues as this will be strictly inhouse tool only.
Sample of the variable
$schools = array(
"PHCS"=> array(
"full_name"=> "Pacific Hills Christian School",
"version"=> "4.0.2b",
"etc"=> "etc"
),
"WAC"=> array(
"full_name"=> "Wollondilly Anglican College",
"version"=> "4.0.1",
"etc"=> "etc"
),
);
回答1:
You would be looking at using eval() which use of is pretty controversial due to security risks.
I would suggest you use serialize() and unserialize(), or even better, the JSON functions instead.
The JSON encode/decode would be the best option for displaying to the user as it's fairly readable.
回答2:
Following the advice on php.net, if you plan to change the object you should use serialize and unserialize:
$var = serialize(array('hello'));
// string(22) "a:1:{i:0;s:5:"hello";}"
var_dump( unserialize($var) );
来源:https://stackoverflow.com/questions/9323485/whats-the-opposite-of-var-export-function-in-php