【发布时间】:2014-07-31 16:12:19
【问题描述】:
我是 PHP 文件函数的新手,我正在尝试写入 以这种方式归档。数据是从 Instagram 实时发布的 订阅源。该文件似乎总是包含一个空行 通常在前几行收到。
$x = fopen('activity.log', "r+");
$myString = file_get_contents('php://input');
$ALL = $myString."\n";
file_put_contents('activity.log', $ALL, FILE_APPEND);
所以,我尝试用 FILE_SKIP_EMPTY_LINES 参数创建数组时使用 file() 函数,但是空行(在本例中为第 5 行) 在数组中显示为空元素。
$x = fopen('activity.log', "r+");
//put file contents into an array
$y = file('activity.log', FILE_SKIP_EMPTY_LINES);
echo "<pre>";print_r($result);"</pre>";
Array
(
[0] => [{"changed_aspect": "media", "object": "tag", "object_id": "london", "time": 1406820800, "subscription_id": 9720966, "data": {}}]
[1] => [{"changed_aspect": "media", "object": "tag", "object_id": "london", "time": 1406820802, "subscription_id": 9720966, "data": {}}]
[2] => [{"changed_aspect": "media", "object": "tag", "object_id": "london", "time": 1406820803, "subscription_id": 9720966, "data": {}}]
[3] => [{"changed_aspect": "media", "object": "tag", "object_id": "london", "time": 1406820803, "subscription_id": 9720966, "data": {}}]
[4] =>
)
我还尝试了 array_filter() 来删除空元素,但这不起作用,所以我认为空行实际上并不是空的。什么 我可能会在这里失踪。谢谢。
【问题讨论】: