我使用preg_match_all()
抓住從頁面的電話號碼,但我得到的錯誤preg_match_all() [function.preg-match-all]: Compilation failed: nothing to repeat at offset 20
PHP的正則表達式(XXX)XXX-XXXX
我的PHP代碼:
preg_match_all(
'/<div class="phone">(*.?)<\/div>/s',
$html,
$array,
PREG_SET_ORDER
);
代碼到正則表達式:
<div class="phone">
(617) 495-5758
</div>
爲什麼在電話號碼犯規(*.?)
工作,和h我可以編輯代碼以使其正確處理電話號碼嗎?
[提取電話號碼]的可能重複(http://stackoverflow.com/questions/3982186/extracting-phone-numbers) – coreyward
我假設你的網站是美國專用,但爲了防止您計劃在其他地方使用此代碼,請注意,世界其他地區不會像這樣格式化他們的電話號碼。 – Spudley
此外,這是在'preg_match' [文檔](http://us3.php.net/manual/en/function.preg-match.php#90503)的評論。你應該知道足夠使它適用於'preg_match_all'。 – coreyward