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. Link to comment https://forums.phpfreaks.com/topic/20488-remove-every-image-tag-in-a-string-solved/ 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 Link to comment https://forums.phpfreaks.com/topic/20488-remove-every-image-tag-in-a-string-solved/#findComment-90315 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 ;) Link to comment https://forums.phpfreaks.com/topic/20488-remove-every-image-tag-in-a-string-solved/#findComment-90323 Share on other sites More sharing options...
ale1981 Posted September 13, 2006 Author Share Posted September 13, 2006 Works great ;) Link to comment https://forums.phpfreaks.com/topic/20488-remove-every-image-tag-in-a-string-solved/#findComment-91085 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? Link to comment https://forums.phpfreaks.com/topic/20488-remove-every-image-tag-in-a-string-solved/#findComment-91088 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]. Link to comment https://forums.phpfreaks.com/topic/20488-remove-every-image-tag-in-a-string-solved/#findComment-91096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.