Is it possible to use str_Replace for a dynamic string?

Discussion in 'PHP' started by ridesign, Mar 7, 2009.

  1. #1
    I have a string:

    <!--START name abc from domain.com.--> <a href="http://www.mysite.com"><img src="http://www.mysite.com" border="0"></a> <!--END MERCHANT:name abc from domain.com-->

    I want to replace everything between the start <!-- --> tags and also at the end I want to replace everything in the <!-- --> including the tags themselves.

    I tries using str_replace, but my problem is the abc is a variable so it keeps changing in every record.
     
    ridesign, Mar 7, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $str = preg_replace('/<!--start.*?-->/i', '<p>replacement for START</p>', $str);
    Code (markup):
    Learn preg. It's the heart of the solution to a great many tasks.
     
    SmallPotatoes, Mar 8, 2009 IP
    ridesign likes this.
  3. ridesign

    ridesign Peon

    Messages:
    294
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, its works great, are there any websites you would recommend to learn preg?
     
    ridesign, Mar 8, 2009 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    ads2help, Mar 8, 2009 IP