SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict peterb's Avatar
    Join Date
    Jun 2003
    Location
    Athens, Greece
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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'&gt;


    Can someone tell me what I am doing wrong?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    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....

  3. #3
    SitePoint Addict peterb's Avatar
    Join Date
    Jun 2003
    Location
    Athens, Greece
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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$postsPREG_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.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    So... you're trying to completely obliviate the image tags?
    PHP Code:
    $str preg_replace("~<br><img (.*?)>~","",$str); 

  5. #5
    SitePoint Addict peterb's Avatar
    Join Date
    Jun 2003
    Location
    Athens, Greece
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That did it.

    Many thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •