Php 文件\u跳过\u空\u元素不删除空行

Php 文件\u跳过\u空\u元素不删除空行,php,arrays,file,Php,Arrays,File,我是PHP文件函数的新手,我正在尝试编写一个 以这种方式归档。数据从Instagram实时发布 订阅源。文件似乎总是包含一个空行 通常在收到的前几行 $x = fopen('activity.log', "r+"); $myString = file_get_contents('php://input'); $ALL = $myString."\n"; file_put_contents('activity.log', $ALL, FILE_APPEND); 因此,我尝试使用

我是PHP文件函数的新手,我正在尝试编写一个 以这种方式归档。数据从Instagram实时发布 订阅源。文件似乎总是包含一个空行 通常在收到的前几行

  $x = fopen('activity.log', "r+");
  $myString = file_get_contents('php://input');
  $ALL = $myString."\n";
  file_put_contents('activity.log', $ALL, FILE_APPEND);
因此,我尝试使用 使用创建数组时,文件\u跳过\u空\u行参数 文件函数,但本例中的空行为第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来删除空元素,但这不起作用,所以我认为空行实际上不是空的。什么
我可能在这里失踪了。谢谢。

那里面还有其他的空间,不仅仅是一条新线。 一个简单的解决方法是使用以下内容对其进行过滤:

^\s*$检查数组行中是否只有空格,而_INVERT只返回那些没有空格的行

顺便说一句,你不需要事先的fopen

  preg_grep("/^\s*$/", file($fn), PREG_GREP_INVERT)