Regex to remove <img>
Posted on 2006-04-25
Hi everybody. This question might be a little bit more than what it seems. I need a regular expression to remove HTML image tags. Sure. Easy enough. Why not something like this, right?
$html = preg_replace('/<img[^>]*>/i', '', $html);
Except I was reading a website that pointed out to me the possibility that there's a greater-than sign (>) in the alt-attribute. And in that case, the command above would change something like this:
<img src="next.jpg" alt=">">
But clearly, I'd like it to delete all of that with one fell-swoop. So I'm looking for a similar regular expression replacement to accomodate for greater-than signs in the alt attribute (but remember, there's always a possibility that the alt-attribute isn't even there to begin with). This has probably already been addressed somewhere, but I had a few extra points to give away. Thanks.