REGEX for finding and replacing IMG elements

Possible duplicate:
I am looking for a regex to remove a given (x) HTML tag from a string

I have a long HTML file and I need to remove all the <img /> tags inside it and all the <a><img /></a> bindings.

I am thinking of writing a PHP script that does this work. But each image and link have different number attributes, so I donโ€™t know how I can do it neatly. Any help would be greatly appreciated.

+4
source share
3 answers

Thanks for the answers guys, this is the final solution I was looking for.

 $text = preg_replace("/<a[^>]+\><img[^>]+\><\/a>\n/i", "", $text); $text = preg_replace("/<img[^>]+\>/i", "", $text); 
+4
source

Use a DOM parser, such as PHP Simple HTML DOM Parser or PHP DOM

+2
source

try <img[^>]+/>

+1
source

All Articles