简体   繁体   English

PHP试图在文本文件中找到一个特定的行并回显它

[英]PHP Trying to find a spefic line in text file and echo it

So I am trying to find a list of steam ID's in a scraped html file. 所以我试图在一个已删除的html文件中找到一个蒸汽ID列表。 This is what I have so far but it's not working, it is parsing an html page I saved as text and supposed to be outputting things with below variables and it is outputting a blank page. 这是我到目前为止,但它没有工作,它正在解析我保存为文本的html页面,并且应该输出带有下面变量的东西,并且它输出一个空白页面。

   <?php
$filein = file('TF2U.txt');
foreach ($filein as $html) {
    $pattern = '#.*<a[^>]+href="steamcommunity.com/profiles/([0-9]+)/"#iA';
    $matches = NULL;
    $match_count = preg_match_all($pattern, $html, $matches);
    if ($match_count > 0) {
        echo implode($matches[1]);
        echo "<br>\n";
        }
}
?>

Any help would be awesome, I am not sure what I am missing but it's probably simple. 任何帮助都会很棒,我不知道我错过了什么,但它可能很简单。

The problem is that the links aren't ending with a / , so here's a solution with some tweaks: 问题是链接不是以/结尾,所以这里是一个带有一些调整的解决方案:

$file = file_get_contents('TF2U.htm');
preg_match_all('#<a.*?href="(?:http://)steamcommunity.com/profiles/(?P<id>\d+)[^‌​>]+#msi', $file, $matches);
print_r($matches['id']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM