[英]Read saved text from a file an array in php
I have created a script that generates an array. 我创建了一个生成数组的脚本。 This array needs to be stored so that if a user wants to export its contents( eg print ) it may be possible.
该数组需要存储,以便如果用户想要导出其内容(例如print),则可能是可行的。
This is my array ($doc) 这是我的数组($ doc)
Array
(
[0] => Array
(
[0] => ------
[1] => ---Start----
[2] => -------
[3] => Generated on Saturday, 3rd, August 2013
)
[1] => Array
(
[0] => ------
[1] => -------
[2] => -------
[3] => -----------------------
)
[2] => Array
(
[0] => Tid
[1] => Policy
[2] => Budget
[3] => User
[4] => Capturetime
[5] => Country
)
[3] => Array
(
[0] => 1
[1] => ask
[2] => das
[3] => carol
[4] => 2013-07-09
[5] => Ethiopia
)
[4] => Array
(
[0] => 2
[1] => das
[2] => adsasd
[3] => ck
[4] => 2007-07-13
[5] => Slovakia
)
[5] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
[6] => Array
(
[0] => ------
[1] => ---End----
[2] => -------
)
)
Now I save the array to a file: 现在,我将数组保存到文件中:
file_put_contents('array.txt', print_r($printdoc, true));
Then I would like to call back the contents of array.txt to the array $printdoc and use it as an array. 然后,我想将array.txt的内容回调到数组$ printdoc并将其用作数组。
$printdoc = file_get_contents('array.txt', true);
I get $printdoc as a string instead of an array 我得到$ printdoc作为字符串而不是数组
Any help? 有什么帮助吗?
You can use serialize() to convert your array into a serializable string, then store it in a file. 您可以使用serialize()将数组转换为可序列化的字符串,然后将其存储在文件中。 When you read the string from the file use unserialze() to convert it back into an array.
从文件中读取字符串时,请使用unserialze()将其转换回数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.