Suppose I have two links in my content. How can I find the specific links containing the $string and replace with words only.
$string = 'dog';
$content = 'a quick brown <a href="some-link"> fox</a> jumps over a lazy <a href="another-link"> dog</a>';
$new_content = preg_replace('<a.+href="(.*)".*> '.$string.'</a>', $string, $content);
I have tried with '~<a.+href="(.*)".*> '.$string.'</a>~' but its removing all the content between those anchors too.
Whats wrong ?
update:
replace <a href="another-link"> dog</a> with dog only and leave <a href="some-link"> fox</a> as it is.