Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

array (
  'IMType' => '1',
  'Email' => '[email protected]',
  '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?

like image 244
omg Avatar asked Jun 01 '09 03:06

omg


1 Answers

like this:

$dumpStr = var_export($var,true);
eval('$somevar = ' . $dumpStr.';');
like image 64
Jonathan Fingland Avatar answered Sep 18 '22 14:09

Jonathan Fingland