我有一些基本的HTML,我打電話str_replace()
,我需要追加HTML字符串中找到的所有網址'generate_book.php?link=
',但我需要排除任何外部鏈接,例如;什麼是PHP正則表達式來定位某些URL?
<a href="gst/3.html">Link</a>
- 這應該成爲 - <a href="generate_book.php?link=gst/3.html"></a>
<a href="http://example.com">Link</a>
- 這應該被單獨留在家中
你的大腦POWA表示讚賞!
我敢肯定,你不能只是一個函數作爲一個字符串在那裏。你想要的是`preg_replace_callback()`和`create_function()`(如果使用> 5.3則使用匿名函數)。 – alex 2010-11-30 01:48:03
`e`修飾符使`replace`參數被評估爲PHP代碼[PHP.net PCRE修飾符](http://uk3.php.net/manual/en/reference.pcre.pattern.modifiers.php) – 2010-11-30 01:52:11