2012-03-17 33 views
1

我想做一個preg_match_all捕獲具有free file的錨文本的鏈接的href。正則表達式的幫助,獲取與某些錨文本的鏈接

這是我迄今爲止<a.+href="(.*)".*>free file</a>但其沒有工作,因爲我得到的錯誤...

警告:的preg_match()[function.preg匹配]:未知的修飾詞「F 'in /home/aaran/public_html/tests/free_file.php on line 20

任何人都可以幫助我。

詩IM想匹配來自這個網址...

<p> Grab this month's <a href="/item/html5-image-transitions-jquery-plugin/571431?WT.ac=free_file&amp;WT.seg_1=free_file&amp;WT.z_author=pixelentity">free 
file</a> from the Canvas category! </p> 

回答

3

這個問題似乎是你沒有把你的周圍表達式分隔符。 PHP要求表達式被某種形式的有效分隔符包圍。常見的有:

  • /,通常使用的,除非有特別的理由不這樣做
  • ~
  • #

因此,請確保您的preg_match開始是這樣的:

preg_match('~<a.+href="(.*)".*>free file</a>~', /* ... */ 

請注意,我用由於在表達式中有/,因此可以將其作爲分隔符。

+0

謝謝sooo多。 – 2012-03-17 21:06:37