多个 url 的 Preg_match 值 url 计数

在找不到更多结果之前,我如何进行 preg_match?


我正在使用文件获取内容


例如我正在使用这个网址


$updated_url = "https://www.testcompany.com/count=1";


$html2 = file_get_contents($updated_url);  

preg_match_all('/<ul class="standard">(.*?)<\/ul>/s', $html2, $test);

1) 如果 > preg_match 为真 > 在 url 中添加 count = +1(转到https://www.testcompany.com/count=2 url)并检查 preg 匹配值是否为真。


2) 循环 If 直到 preg_match 为假。


我想获取与 preg 匹配值匹配的最后一个 url。


qq_笑_17
浏览 146回答 1
1回答

斯蒂芬大帝

你可以尝试这样的事情:<?phpconst URL_PATTERN = 'https://www.testcompany.com/count=%s';$regex = '/<ul class="standard">(.*?)<\/ul>/m';$previousMatchList = [];$matchList = [];for ($count = 1; ; $count++) {&nbsp; &nbsp; $html2 = file_get_contents(sprintf(URL_PATTERN, $count));&nbsp; &nbsp; preg_match_all($regex, $html2, $matchList);&nbsp; &nbsp; if (!array_filter($matchList)) {&nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; }&nbsp; &nbsp; $previousMatchList = $matchList;}$lastValue = array_pop($previousMatchList[0]);var_dump($lastValue);
打开App,查看更多内容
随时随地看视频慕课网APP