regex - PHP Match phrase only if outside of an <a href> tag -
i'm trying automate internal links within pages on website. need linked text exempted.
for following example should replace bolded text (example).
<a class="example" href="http://www.example.com/">example</a> <p>new **example**</p>
i tried following didn't work.
$re = '/(\b'.$search.'\b)+((?=.*<a)|(?!.*<\/a>))/'; $str=preg_replace($re, $replace, $text);
you should follow @thomasayoub's advice. use dom functionalities achieve such task way match desired word regular expressions if want see:
<a\b[^>]+>.*?<\/a>\k|example
Comments
Post a Comment