Due to the lack of code, I will make a few assumptions.
These will be changed when the needed code is added.
There is no information about how that file was created.
The output looks like it came from either var_dump()
or print_r()
.
I'm not entirely sure of which was used.
If these were used, forget the file.
If you want to recover this file, you have to manually convert it into actual working code (by adding quotes around the key names in the arrays), add return
(with space after) to the file and include
it.
To re-do the file, and for the next time you write it, you have several methods:
Use the function serialize()
:
This is easy to use!
Simply pass the variables and you are set.
Here's an example:
$text=serialize($variable);
Then you use unserialize()
to extract the data.
Like this:
$data=unserialize($text);
Use json_encode()
to save the data.
It works the same way:
$text=json_encode($data);
And use json_decode()
to get the data back, like this:
$data=json_decode($text);
Notice that the JSON data can be used in many other languages, including Javascript!
Also, this method is faster than serialize()
.
Use var_export()
to get valid PHP code in a string.
Like this:
$php=var_export($data);
//write the file like this, prepending '<?php return ' to it:
file_put_contents('file.php','<?php return '.$php);
Which will write something like:
return Array(1,2,3); //example code.
To read the file, simply use include
or require
:
$data=include 'file.php';
Yes, include can receive the array data!
This is, by far, the fastest method!