我想回到跨度HTML標籤之間的數字。這個數字可能會改變!函數的困難preg_match_all
<span class="topic-count">
::before
"
24
"
::after
</span>
我試過下面的代碼:
preg_match_all("#<span class=\"topic-count\">(.*?)</span>#", $source, $nombre[$i]);
但它不工作。
整個代碼:
$result=array();
$page = 201;
while ($page>=1) {
$source = file_get_contents ("http://www.jeuxvideo.com/forums/0-27047-0-1-0-".$page."-0-counter-strike-global-offensive.htm");
preg_match_all("#<span class=\"topic-count\">(.*?)</span>#", $source, $nombre[$i]);
$result = array_merge($result, $nombre[$i][1]);
print("Page : ".$page ."\n");
$page-=25;
}
print_r ($nombre);
不要使用REGEX進行HTML PARSING!首先得到你的跨度值,然後使用正則表達式......! – Random
添加s修飾符,使點也匹配換行符。編輯:+1隨機說的。 ;) – Connum
另外,如果你只想要一個數字匹配\ d + – Gordon