Php 替换<;a href=";mailto:只需发送电子邮件即可
我想用普通电子邮件替换html中的所有“mailto:”链接Php 替换<;a href=";mailto:只需发送电子邮件即可,php,regex,mailto,Php,Regex,Mailto,我想用普通电子邮件替换html中的所有“mailto:”链接 In: text .... <a href="mailto:somebody@example.org">not needed</a> text Out: text .... somebody@example.org text In:text。。。。文本 输出:文本。。。。somebody@example.org正文 我这样做: $str = preg_replace("/\<a.+href=\"mai
In: text .... <a href="mailto:somebody@example.org">not needed</a> text
Out: text .... somebody@example.org text
In:text。。。。文本
输出:文本。。。。somebody@example.org正文
我这样做:
$str = preg_replace("/\<a.+href=\"mailto:(.*)\".+\<\/a\>/", "$1", $str);
$str=preg\u replace(“/\
输出:somebody@example.org">
通过将?
添加到量词+
和*
中,使您的匹配非贪婪,如下所示:
$str = preg_replace("/\<a.+?href=\"mailto:(.*?)\".+?\<\/a\>/", "$1", $str);
谢谢,非贪婪匹配做得很好&谢谢你的转义信息。
$str = preg_replace("/\<a.+?href=\"mailto:(.*?)\".+?\<\/a\>/", "$1", $str);
$str = preg_replace('#<a.+?href="mailto:(.*?)".+?</a>#', "$1", $str);