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?
like this:
$dumpStr = var_export($var,true);
eval('$somevar = ' . $dumpStr.';');
Perhaps you want to serialize object and then unserialize?
http://php.net/serialize
This technique is good for data cache.
< ?php
// reading data from DB or an API webservice etc.
$arrName = array();
$arrName = call_procedure_here();
$strFileContent = "<"."?php".PHP_EOL."$"."arrName = ".var_export($arrName, true).PHP_EOL."?".">";
file_put_contents('cache_folder/arrayfilename.php', $strFileContent);
...
//later... from another process;
include 'cache_folder/arrayfilename.php';
?>
I wrote a basic var_export
parser, without eval: VarExportParser.php
Usage:
require_once('VarExportParser.php');
$parsed = VarExportParser::parse("array ('IMType' => '1', 'Email' => 'test@gmail.com')");
print(json_encode($parsed).PHP_EOL);
Outputs:
{"IMType":"1","Email":"test@gmail.com"}
You can try js version of it here: text_transform.html (the var_export to json button)
its very simple , you must save it as php file not txt and then
just iclude it inside a variable :)
like this:
file_put_contents( '/some/file/data.php', '<?php return '.var_export( $data_array, true ).";\n" );
when you need to access it just do this :
$data = include '/some/file/data.php'