I want to remove links (keeping text) from a string only if the text inside the link match exactly a term.
I'm not sure what's wrong with this regexp, but it strips out a lot of text.
$terms = ["justo pulvinar"];
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed <a href=\"#/app/292\">quam nibh, faucibus</a> quam nibh, faucibus eget tortor eget, finibus semper justo. aliquet <a href=\"#/app/212\">justo pulvinar</a>, elit.";
foreach ($terms as $term) {
$string = preg_replace('/<a href=\"(.*?)\">('.$term.')<\/a>/', "\\2",$string);
}
echo $string;
Edit maybe I wasn't clear enough, I have a $terms
array for a reason: I want to remove from $string
links that match exactly those terms, not all links.