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 > 

live demo

through pcre verb (*skip)(*f).

<[^<>]*>(*skip)(*f)|[a-z0-9._%+-]+@([a-z0-9.-]+\.[a-z]{2,4}|[a-z0-9.-]+) 

demo

<[^<>]*> 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

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -