+
95
-

回答

如何担心url需要编码可以使用preg_replace_callback方法,代码如下:

,<?php

function change_a_url($matches) {
return "<a href=".urlencode($matches[1]).">".$matches[2]."</a>";
}

$content = '什么,<a href="http://baidu.com">点击打开外链</a>,第二个链接<a href="http://baidu.com">点击打开外链</a>没了';


echo preg_replace_callback(
"/<[a|A].*?href=[\'|\"](.*?)[\'|\"].*?>(.*?)<\/[a|A]>/",
"change_a_url",
$content);

?>


网友回复

我知道答案,我要回答