我想用正則表達式從HTML文件中提取多個URL。 該文件中還有其他URL,做我唯一的模式是「tableentries」。和 「」PHP正則表達式HTML - 提取URL
HTML代碼示例:
<tr class="tableentries2">
<td>
<a href="http://example.com/all-files/files/00000000789/">Click Here</a>
</td>
PHP我寫道:
$html = "value of the code above"
if(preg_match_all('/<td>.*</td>/', $html, $match)){
foreach($match[0] as $x){
echo $x . "<br>";
}}
你的問題是什麼呢?這段代碼給你帶來了什麼?爲什麼它不起作用? – talnicolas
您的HTML屬性缺少引號。 'tr class =「tableentries2」> ... ' (edited your question) –
Maybe be use an DOM parser like http://simplehtmldom.sourceforge.net/ –