Possible Duplicate:
PHP – remove <img> tag from string
I have my content like this:
$content = '<p> </p>
<p><img width="645" height="450" src="/proshore/userfiles/image/1.jpg" alt="" /></p>
<p>An explorer adventures into an unknown world, yet it seems that he has been there before. A short animated film directed by Malcolm Sutherland in 2010. With music by Alison Melville and Ben Grossman, and foley by Leon Lo. Sound design / mix by Malcolm Sutherland.</p>
<p>The animation is all hand-drawn; a mix of drawing / pastels on paper and digital animation with Toonboom Studio and a wacom cintiq tablet, assembled in After Effects 7 and edited in Sony Vegas 8.</p>
<p> </p>';
I want the output ignoring the <img> tag. I tried some messups with preg_replace but didn’t work.. It will be a great help if someone can explain me how it works.
If you are not forced to use regular expressions to parse HTML content, then I’d suggest using PHP’s
strip_tags()function along with itsallowed_tagsargument.This will tell PHP to remove all the html tags and leave the ones your specified in the
allowed_tags.Example usage taken from the documentation –
So, if you simply specify all the HTML tags in
allow_tagsexcept the<img>tag, you should get the results that you need – only removing the<img>tag from your string.