Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 替换<;a href=";mailto:只需发送电子邮件即可_Php_Regex_Mailto - Fatal编程技术网

Php 替换<;a href=";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

我想用普通电子邮件替换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=\"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);