Skip to content
Advertisement

how to clear all non-jpg img tags from a string

How to clear all tags from an HTML string from files that do not have a jpg or gif extension in PHP

I have to remove all img tags from a string, where the extension of the src is not jpg or gif.

So far I tried:

JavaScript

but this is slow and it only removes the source.

Advertisement

Answer

Well, DOMDocument is not going to be particularly fast. If you want to remove the image and not just its src, try:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement