I would like to strip all img tags from a certain text, except for those which contain a certain keyword (e.g. the domain they’re hosted at).
Here’s what I’ve come up with, but I’m afraid it doesn’t work:
$text = preg_replace("/<img[^>]+(?!keyword)[^>]+\>/i", "", $text);
Any help would be GREATLY appreciated! 🙂
Use a callback to simplify the task:
If you are working on HTML snippets using phpQuery/QueryPath would still be possible, but adds more post-processing.