remove .*& from string

Discussion in 'PHP' started by myinnet, Nov 24, 2006.

  1. #1
    i wan to remove all the *&^@%^#.... from a string, just want to keep the letters and number.
    eg:
    $str="test#@dd_22345(eer)..";
    i want it to be :
    "testdd22345eer"
    hope it's easy to understand,
    thanks
     
    myinnet, Nov 24, 2006 IP
  2. lbalance

    lbalance Peon

    Messages:
    381
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $new_str = ereg_replace("[^A-Za-z0-9]", "", $str);
    
    PHP:
     
    lbalance, Nov 24, 2006 IP
  3. sultancillo

    sultancillo Peon

    Messages:
    35
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $str="test#@dd_22345(eer)..";
    $symbols = array("*","&","^","@","%","^","#");
    $str = str_replace($symbols,"",$str);
    PHP:
    if there are additional symbols you want to filter add them to the $symbols array
     
    sultancillo, Nov 24, 2006 IP
  4. myinnet

    myinnet Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you for them, it's works:)
     
    myinnet, Nov 24, 2006 IP