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.
<img />
<a><img /></a>
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.
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);
Use a DOM parser, such as PHP Simple HTML DOM Parser or PHP DOM
try <img[^>]+/>
<img[^>]+/>