php - how to replace email address from html innertext -
i have problem, replacing email address html innertext.
i can replace email address. can't replace specific(innertext of html). please me..
i have tried preg_replace('/[a-z0-9._%+-]+@([a-z0-9.-]+\.[a-z]{2,4}|[a-z0-9.-]+)/iu','[---]',$data)
please me. thanks...
my input
<div  data="example1@dom.com,example4@dom.com"><a href="example1@dom.com" > example4@dom.com,  <b>example3@dom.com</b>  other text, example7@dom.com, ,<i>example5@dom.com</i></a></div >   expected output:
<div  data="example1@dom.com,example4@dom.com"><a href="example1@dom.com" > [--],  <b>[--]</b>  other text, [--] ,<i>[--]</i></a></div >        
through pcre verb (*skip)(*f).
<[^<>]*>(*skip)(*f)|[a-z0-9._%+-]+@([a-z0-9.-]+\.[a-z]{2,4}|[a-z0-9.-]+)     <[^<>]*> matches tags , following pcre verb (*skip)(*f) makes match fail completely. regex engine tries match pattern @ right of | symbol against remaining string.
$re = "/<[^<>]*>(*skip)(*f)|[a-z0-9._%+-]+@([a-z0-9.-]+\\.[a-z]{2,4}|[a-z0-9.-]+)/mi"; $str = "<div data=\"example1@dom.com,example4@dom.com\"><a href=\"example1@dom.com\" > example4@dom.com, <b>example3@dom.com</b> other text, example7@dom.com, ,<i>example5@dom.com</i></a></div >\n"; $subst = "[---]"; $result = preg_replace($re, $subst, $str); echo $result;   output:
<div data="example1@dom.com,example4@dom.com"><a href="example1@dom.com" > [---], <b>[---]</b> other text, [---], ,<i>[---]</i></a></div >      
Comments
Post a Comment