[英]PHP Trying to find a spefic line in text file and echo it
所以我試圖在一個已刪除的html文件中找到一個蒸汽ID列表。 這是我到目前為止,但它沒有工作,它正在解析我保存為文本的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";
}
}
?>
任何幫助都會很棒,我不知道我錯過了什么,但它可能很簡單。
問題是鏈接不是以/
結尾,所以這里是一個帶有一些調整的解決方案:
$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.