ale1981 Posted September 12, 2006 Share Posted September 12, 2006 This is probably very simple, but I havent got a clue where to start when it comes to preg_replace! What I need is to completely remove any <img> tags from a string and everything in between the tag. Quote Link to comment Share on other sites More sharing options...
Jenk Posted September 12, 2006 Share Posted September 12, 2006 strip_tags() to remove all html tags.[code]<?php$string = preg_replace('/<(\s*)img[^<>]*>/i', '', $string);?>[/code]to remove just img Quote Link to comment Share on other sites More sharing options...
ale1981 Posted September 12, 2006 Author Share Posted September 12, 2006 Thanks Jenk will give that a go ;) Quote Link to comment Share on other sites More sharing options...
ale1981 Posted September 13, 2006 Author Share Posted September 13, 2006 Works great ;) Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 13, 2006 Share Posted September 13, 2006 I think I might as well ask this now. All the str replaces I've seen for filtering out HTML / XML tags have these huge lumps of characters, but I don't know /<(\s*)img[^<>]*>/i works. Can you give a slight explanation? Quote Link to comment Share on other sites More sharing options...
effigy Posted September 13, 2006 Share Posted September 13, 2006 [b]Jenk:[/b] A few nitpicks. Don't use[tt] ( ) [/tt]if you're not going to use what is captured; use[tt] (?: ) [/tt]instead. White space does not need to be searched for before "img", this is invalid HTML.[quote author=Wintergreen link=topic=107754.msg433470#msg433470 date=1158159232]Can you give a slight explanation?[/quote][code]/ <img ### Match this literally [^>]* ### Match any character 0 or more times that is not > > ### Match this literally/xi[/code]The[tt] /x [/tt]and[tt] /i [/tt] modifiers are explained [url=http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php]here[/url]. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.