omg omg - 3 months ago 19
PHP Question

how to read output of var_export into a variable in PHP?

the output is like below restored in a output.txt file:

array (
'IMType' => '1',
'Email' => 'test@gmail.com',
'SignupName' => 'test11',
'Password' => '11111',
'Encrypted' => '',
'Confirm' => '11111',
'OldPassword' => '',
'Name' => 'test',
'SignupProvinceText' => 'province',
'SignupCity' => 'cityname',
'Street' => 'street x.y',
'SignupIndustry' => 'IT',
'SignupCompany' => 'jobirn',
'SignupJt' => 'engineer',
'CellPhoneNum' => '',
'linked_in' => '',
)


it's in fact output of
var_export(my_variable,true)
,but how to read it into a variable again?

Answer

like this:

$dumpStr = var_export($var,true);
eval('$somevar = ' . $dumpStr);
Comments