Forum Moderators: coopster

Message Too Old, No Replies

Regex remove image

         

tuuni

2:18 pm on Feb 25, 2011 (gmt 0)

10+ Year Member



How to remove this whole line of code with regex or any other function.

<img src="http://sub.domain.com/~r/mycat/~4/eOfsX2pdMHU" alt="" width="1" height="1" />

Dynamic content is marked with bold text.


Sorry, i am beginner in this matter.

Thank You!

rocknbil

4:38 pm on Feb 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You want to remove the whole <img>, or just the bolded part? The bolded part is a little more complex, but the whole <img> is fairly straightforward. Anything that starts with <img (case insensitive) followed by one or more of anything NOT a > and ending with a >.

$text = preg_replace('/<img[^>]+>/ism','',$text);

The m and s cumulatively match/replace multiple lines and newlines, hence this would zap all images out of a given page.

tuuni

7:17 pm on Feb 25, 2011 (gmt 0)

10+ Year Member



Thank you for your input.

Yes, i would like to remove the whole row completely.

Note that i do not want to remove all "<img>" tags globally, but only the pattern i mentioned which starts with "<img src="http://sub.domain.com/~r/mycat/".

Thanks for your support..

tuuni

10:55 am on Feb 27, 2011 (gmt 0)

10+ Year Member



Any help is much appreciated!