Page 1 of 1

RegEx help needed (remove certain images)

Posted: Tue Jan 04, 2005 4:33 am
by tylerdurden
Hi all!

I've arrived at a dead and and could need some help. RegExs are giving me headaches again.
I need to cleanup some text to only allow images from a certain server.
Let's say the text looks like this:

Code: Select all

Some html code
<img src="http://www.allowedserver.com/pics/image.jpg" border="0">
<img src="http://www.deniedserver.com/pics/image.jpg" border="0">
more html code
I need a regex that will remove the whole image tag that contains the image from the http://www.deniedserver.com but leaves the other image intact.

Any help appreciated! Thanks!

tylerd

Posted: Tue Jan 04, 2005 9:09 am
by feyd

Code: Select all

preg_replace('#&lt;\s*img\s+&#1111;^&gt;]*src\s*=\s*(&#1111;"'']?)(http://)?(&#1111;a-z-]+\.)*(?!allowedserver.com)(/&#1111;^/]+)*\\\\1&#1111;^&gt;]*?&gt;#is', '', $text);