str_replace help

Discussion in 'PHP' started by baris22, Jan 2, 2009.

  1. #1
    hello,

    I need to replace a sentence. The problem is the sentence changes all the time, the beginning and the end of the sentence remain same.

    the is the sentence i need to replace

    
    
    File added on Wed Dec 31, 2008 3:51 am [by admin]
    
    
    PHP:
    File added on and [by admin] does not change but the date changes on every entry.

    How can i find and change the all sentence?

    Thanks
     
    baris22, Jan 2, 2009 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You would have to use regex which means preg_replace would be your best bet. :)

    $new_string = preg_replace("#File added on (.+?) \[by admin]#i", "replace with this", $text_to_search);
    PHP:
     
    zerxer, Jan 2, 2009 IP