Replaceing <a href="mailto: with just email aadress

Posted by Lauri on Stack Overflow See other posts from Stack Overflow or by Lauri
Published on 2010-03-27T15:41:21Z Indexed on 2010/03/27 15:43 UTC
Read the original article Hit count: 376

Filed under:
|
|

I want to replace all "mailto:" links in html with plain emails.

In: text .... <a href="mailto:[email protected]">not needed</a> text
Out: text .... [email protected] text

I did this:

$str = preg_replace("/\<a.+href=\"mailto:(.*)\".+\<\/a\>/", "$1", $str);

But it fails if there are multiple emails in string or html inside "a" tag

In: <a href="mailto:[email protected]">not needed</a><a href="mailto:[email protected]"><font size="3">[email protected]</font></a>
Out: [email protected]">

© Stack Overflow or respective owner

Related posts about php

Related posts about regex