Try this to replace the anchor text to given string with preg_replace,$string = 'dog';$content = 'a quick brown <a href="some-link"> fox</a> jumps over a lazy <a href="another-link"> dog</a>';echo preg_replace('/<a(.+?)>.+?<\/a>/i',"<a$1>".$string."</a>",$content);
↧
Answer by user3040610 for How to replace specific tag with regex in php?
↧