string Replacement

Discussion in 'PHP' started by Luke Jones, Jul 18, 2007.

  1. #1
    Hello,
    Could you please confirm that the following is correct for replacing a string of numbers:
    $old_string = "pub-([A-Za-z0-9]+)";
    $new_string = ereg_replace("[A-Za-z0-9]+", "7185536717731935", $old_string);
    I think I've done something wrong.
    When I've resolved this how do I add it to an existing script. Do I use a Get results command, then apply it to the results?

    Thanks for your help.

    Luke
     
    Luke Jones, Jul 18, 2007 IP
  2. Bryce

    Bryce Peon

    Messages:
    1,235
    Likes Received:
    93
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if you want to replace anything after "pub-" with "7185536717731935" why not just preg_replace("/pub\-.*$/", "7185536717731935", your_string_here)
     
    Bryce, Jul 18, 2007 IP
  3. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is preg_replace("/pub\-.*$/", "7185536717731935", your_string_here)
    all the code I need?
    your_string_here could be anything I define it as, like $replace ?
     
    Luke Jones, Jul 18, 2007 IP