-
str_replace image tags
Hello all,
I am trying to eliminate the following break and image tag:
Code:
<br><img src="/images/grammi.gif" width="100%" height="2px">
using
PHP Code:
$remove = array('\n', '\r', '\t', '<br><img src', '=\"', '\/images\/grammi', '.gif\"', 'width', '=\"', '100', '%\"', 'height=', '\"2px', '\">');
$str = str_replace($remove, "", $str);
but I am seeing the following returned in html:
Code:
='/images/grammi.gif' ='%' '2px'>
Can someone tell me what I am doing wrong?
-
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....
-
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.
PHP Code:
preg_match_all('/<span class="news_home_list">(.*?)<\/span>.*?/s', $html, $posts, PREG_SET_ORDER);
$remove = array("\n", "\r", "\t", "<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.
-
So... you're trying to completely obliviate the image tags?
PHP Code:
$str = preg_replace("~<br><img (.*?)>~","",$str);
-