Possible Duplicate:
How can I replace strings NOT within a link tag?
Hi is there anyone can help me with regular expression
This is the words that i want to replace
$text = '<a href="test-pregnancy.net">pregnancy<a> week by week, some time pregnancy can be very easy';
$search = 'pregnancy';
$replace = '<a href="google-pregnancy.net">pregnancy</a>';
print preg_replace('/('.$search.')/', $replace, $text);
is there any regular expression that except for words that contain inside a link? only replace words that not contain inside a link
I want it would be like this
$text = '<a href="test-pregnancy.net">pregnancy</a> week by week, some time <a href="test-pregnancy.net">pregnancy</a> can be very easy';
How if the condition like this.
$text = '<a href="test-pregnancy.net" title="welcome pregnancy people">pregnancy<a> week by week, some time pregnancy can be very easy';
This will also replace pregnancy in the title of href. Is there any another idea. I want a regex that using exception inside a tag.