【发布时间】:2015-05-07 04:09:58
【问题描述】:
每个例子:
<a href="http://www.google.com">http://www.google.com</a>
转换成
http://www.google.com
在纯文本中使用 php 中的 preg_replace 而不是超链接。
【问题讨论】:
标签: php html preg-replace plaintext
每个例子:
<a href="http://www.google.com">http://www.google.com</a>
转换成
http://www.google.com
在纯文本中使用 php 中的 preg_replace 而不是超链接。
【问题讨论】:
标签: php html preg-replace plaintext
您必须使用以下代码:
$content = '<a href="http://www.google.com">http://www.google.com</a>';
$unlinked_content = preg_replace('#<a.*?>(.*?)</a>#is', '$1', $content);
我对多行链接使用了 's' 修饰符。
但是,如果您要创建清晰的文本,则必须使用 [$1] 之类的东西作为 preg_replace 函数的第二个参数来封装未链接的内容。
如果你想了解正则表达式,我推荐regex101 页面。
【讨论】:
preg_replace('#<a.*?>(.*?)</a>#i', '\1', $text)
【讨论】: