【发布时间】:2020-05-01 18:20:11
【问题描述】:
我正在尝试构建一个 PHP 脚本来逐行读取远程文件并检查是否有某个特定单词然后将其导出。
<?php
$user=strip_tags($_GET['username']);
$pas=strip_tags($_GET['password']);
$data = file_get_contents('URL='.$user.'&password='.$pas.'&type=m3u_plus&output=mpegts', 'r');
$data = explode("\n", $data);
$long=count($data);
$file[0]="#EXTM3U";
$f=2;
$x=2;
while ($x <= $long){
$test=substr($data[$x], 27, 6);
if ($test == "series"){
$file[$f-1]=$data[$x-1];
$file[$f]=$data[$x];
$f=$f+2;
}
$x=$x+2;
}
$file = implode("\n", $file);
?>
我需要脚本在这里检查:
$file[$f-1]=$data[$x-1];
对于 Number : 2020 ,如果存在的话。如果存在则输出,否则继续下一行。
【问题讨论】:
-
问题是什么?
-
我需要过滤数据,只输出包含“2020”的行
标签: php explode line-by-line