0

I'm parsing rss feeds however some feeds have what look to be blank images in them (from feedburner). Can somewhere help me out with a preg_replace command to find and remove an image tag structured like:

<img src="http://feeds.feedburner.com/sdfasdfsfd" height="1" width="1"/>

Thanks!

NullUserException
  • 81,190
  • 27
  • 202
  • 228
Joe
  • 2,773
  • 8
  • 39
  • 55
  • 5
    [Why you can't parse HTML with regex](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – NullUserException Oct 01 '10 at 17:10
  • Remove an image tag? You mean, remove everything from `` ? – chigley Oct 01 '10 at 17:11
  • Why do people always suggest using HTML parsers, whenever someone wants to match/replace something within some html code? Using regular expressions to replace *regular* occurences within some html code is completely fine.. – poke Oct 01 '10 at 17:13
  • @poke: Because [The
    cannot hold it is too late](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)
    – ircmaxell Oct 01 '10 at 17:17
  • @ircmaxell: Might want to read the question and my comment again? This is not about parsing HTML; it is about removing some *regular text* from a string that might contain html tags. – poke Oct 01 '10 at 17:23
  • @poke: Again, that's assuming that this text is regular. It would be quite trivial to write some HTML that would miss most HTML purifiers, but would be turned into something harmful with a regex like this. So this is about parsing HTML... – ircmaxell Oct 01 '10 at 17:27

1 Answers1

4

I guess the "sdfasdfsfd" is something random:

$text = preg_replace( '#<img src="http://feeds.feedburner.com/[a-z]+" height="1" width="1"/>#i', '', $text );
poke
  • 339,995
  • 66
  • 523
  • 574