每exampe为:如何可点击的链接转换成HTML成文字与PHP的preg_replace功能
<a href="http://www.google.com">http://www.google.com</a>
皈依
http://www.google.com
以纯文本格式在PHP中使用的preg_replace不是超链接。
每exampe为:如何可点击的链接转换成HTML成文字与PHP的preg_replace功能
<a href="http://www.google.com">http://www.google.com</a>
皈依
http://www.google.com
以纯文本格式在PHP中使用的preg_replace不是超链接。
preg_replace('#<a.*?>(.*?)</a>#i', '\1', $text)
您必须使用下面的代码:
$content = '<a href="http://www.google.com">http://www.google.com</a>';
$unlinked_content = preg_replace('#<a.*?>(.*?)</a>#is', '$1', $content);
我用了 'S' 修饰符multilined链接。
但是,如果您尝试创建一段清晰的文本,则必须使用[$1]
之类的内容封装未链接的内容作为preg_replace函数的第二个参数。
如果你想了解正则表达式,我推荐regex101页面。
我真的很讨厌那些没有检查答案的人.... – zeflex