str_replace image tags

Hello all,

I am trying to eliminate the following break and image tag:

<br><img src="/images/grammi.gif" width="100%" height="2px">

using

$remove = array('\
', '\\r', '\	', '<br><img src', '=\\"', '\\/images\\/grammi', '.gif\\"', 'width', '=\\"', '100', '%\\"', 'height=', '\\"2px', '\\">');
                $str = str_replace($remove, "", $str);

but I am seeing the following returned in html:

='/images/grammi.gif' ='%' '2px'>

[B]

Can someone tell me what I am doing wrong?[/B]

That did it.

Many thanks

So… you’re trying to completely obliviate the image tags?


$str = preg_replace("~<br><img (.*?)>~","",$str);

Hello StarLion,

Thank you for your response. I changed the single quotes to double but it still did not work.

Here is what I have done now. I use preg_match_all to find the specific area of html that I want to change, then I use the following to delete the img tag.


preg_match_all('/<span class="news_home_list">(.*?)<\\/span>.*?/s', $html, $posts, PREG_SET_ORDER);

$remove = array("\
", "\\r", "\	", "<br><img src", "=\\"", "\\/images\\/grammi", ".gif\\"", "width", "=\\"", "100", "%\\"", "height=", "\\"2px", "\\">");
                $str = str_replace($remove, "", $str);

Unfortunately it still does not work. I tried to eliminate each piece of the img tag and that seems to do it better but then I am left with single quotes for some strange reason rather than the double quotes.

always use double quotes if you’re going to use escape characters, for starters.

I’m getting the feeling you’re actually wanting to preg_match rather than str_replace…