str_replace for * .....

Discussion in 'PHP' started by Adulu, Dec 6, 2010.

  1. #1
    <?php
    $keyword="Hello(greh) thank(rthvf) you(rthvf)";

    $keyword = str_replace("(*)", "", "$keyword");// "*" in stead of (any words) ??

    echo "$keyword";
    ?>
    I'd like to print
    anyone can help me, thank you
     
    Adulu, Dec 6, 2010 IP
  2. underground-stockholm

    underground-stockholm Guest

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can't do this with str_replace(). You need the power of regular expressions to do it:

    $keyword = preg_replace('%\([^()]*\)%s', '', $keyword);
     
    underground-stockholm, Dec 6, 2010 IP
    Adulu likes this.
  3. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it can work.
    thank you so much.
     
    Adulu, Dec 6, 2010 IP
  4. openbytes

    openbytes Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You will need regex
     
    openbytes, Dec 7, 2010 IP
  5. shalini123

    shalini123 Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks for share this information .. its really beneficial for me....
     
    shalini123, Dec 10, 2010 IP