php – 使用正则表达式删除HTML标记
发布时间:2020-12-13 21:36:58 所属栏目:PHP教程 来源:网络整理
导读:我需要转换 $text = 'We had ifun/i. Look at a href="http://example.com"this photo/a of Joe'; [编辑]文本中可能有多个链接. 至 $text = 'We had fun. Look at this photo (http://example.com) of Joe'; 要删除所有HTML标记,并从 a中删除href值.标签需要
我需要转换
$text = 'We had <i>fun</i>. Look at <a href="http://example.com">this photo</a> of Joe'; [编辑]文本中可能有多个链接. 至 $text = 'We had fun. Look at this photo (http://example.com) of Joe'; 要删除所有HTML标记,并从< a>中删除href值.标签需要像上面一样添加. 用正则表达式解决这个问题的有效方法是什么?任何代码片段都会很棒. 解决方法
首先做一个preg_replace来保持链接.你可以使用:
preg_replace('<a href="(.*?)">(.*?)</a>','$2 ($1)',$str); 然后使用strip_tags来完成其余的标签. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |