我已经将外部服务器的响应保存到文本文件中,因此我不需要不断运行连接请求。相反,也许我可以将文本文件用于我的操作目的,直到我准备好重新连接为止。(同时,我的连接请求仅限于这个外部服务器)
这是我保存到文本文件中的内容:
records.txt
Array
(
[0] => stdClass Object
(
[id] => 552
[date_created] => 2012-02-23 10:30:56
[date_modified] => 2012-03-09 18:55:26
[date_deleted] => 2012-03-09 18:55:26
[first_name] => Test
[middle_name] =>
[last_name] => Test
[home_phone] => (123) 123-1234
[email] => someemail@somedomain.com
)
[1] => stdClass Object
(
[id] => 553
[date_created] => 2012-02-23 10:30:56
[date_modified] => 2012-03-09 18:55:26
[date_deleted] => 2012-03-09 18:55:26
[first_name] => Test
[middle_name] =>
[last_name] => Test
[home_phone] => (325) 558-1234
[email] => someemail@somedomain.com
)
)
数组里其实还有更多元素,但我确定选2个就够了。
因为这是一个文本文件,我想假装这是真正的服务器(向我发送相同的信息),那么我怎样才能将它变回真正的数组呢?
我知道我需要先打开这个文件:
<?php
$fp = fopen('records.txt', "r"); // open the file
$theData = fread($fh, filesize('records.txt'));
fclose($fh);
echo $theData;
?>
到目前为止,$theData
是一个字符串值。有没有办法将其转换回最初形式的数组?所需翻译内容:So far $theData is a string value. Is there a way to convert it back to the Array it originally came in as?