tags:

views:

173

answers:

3

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(xxx,true),but how to read it into a variable again?

A: 

like this:

$dumpStr = var_export($var,true);
eval('$somevar = ' . $dumpStr);
Jonathan Fingland
Be *very* careful with eval, and only use it if you are 100% completely sure that the user can't inject any code.
Matthew
agreed about the danger there. hence my comment to Zilupe's answer.
Jonathan Fingland
Also, it should be eval('$somevar = ' . $dumpStr); as + is only used for addition. (If I remember correctly.)
grawity
hahah, quite right. That's what I get for working on javascript all day
Jonathan Fingland
A: 

Why do you need to read it into a variable again? It's already in a variable!

Galen
just updated my question,it's restored in a txt file.
Shore
+4  A: 

Perhaps you want to serialize object and then unserialize? http://php.net/serialize

zilupe
the data structure is restored in a file.can it be directly imported without serialization?
Shore
yes, this is probably what he wants. And is safer than using eval
Jonathan Fingland
yes this is much better than using eval
Galen
@Shore what do you mean by "directly imported without serialization"? Serialization is the process of storing an object. Unserialization is the restoration of the stored object. You can restore objects serialized with anything you wish, but they should follow the format (consult PHP.net)
zilupe