我有一些基本的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