0
我試圖抓住數值(即105),請檢查我的html代碼如下...的preg_match問題
<p>
External Backlinks
</p>
<p style="font-size: 150%;">
<b>105</b>
</p>
,我已經使用正則表達式如下...
$url = 'http://www.example.com/test.html';
preg_match('#<p>External Backlinks</p><p style="font-size: 150%;"><b>([0-9\.]+)#', file_get_contents($url), $matches);
echo $matches[1];
但它沒有返回正確的值,請幫助修復上述正則表達式。謝謝。
http://stackoverflow.com/a/1732454/1163867 – MarcinJuraszek 2012-02-21 21:32:39
對於HTML,請勿使用* regex *,使用* xpath * 。 Xpath是HTML/XML的「常規」表達式,例如'''p [@ style =「font-size:150%;」]/b'。 – hakre 2012-02-21 22:04:35