【问题标题】:PHP check if string contains certain word while explodePHP在爆炸时检查字符串是否包含某些单词
【发布时间】: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 ,如果存在的话。如果存在则输出,否则继续下一行。

【问题讨论】:

标签: php explode line-by-line


【解决方案1】:

你可以使用这个代码结构:

//...  
//your code
$test=substr($data[$x], 27, 6);
if ($test == "series"){

    if (false === strstr($test, '2020')) {
        continue;
    } 

    echo $test;   

    $file[$f-1]=$data[$x-1];
    $file[$f]=$data[$x];
    $f=$f+2;
}
// your code
//...

【讨论】:

    猜你喜欢
    • 2015-03-14
    • 2016-08-09
    • 2018-05-01
    • 2014-01-25
    • 1970-01-01
    • 2014-05-07
    • 2021-07-21
    • 2020-07-06
    • 1970-01-01
    相关资源
    最近更新 更多