I want to remove non standard characters from form input

Discussion in 'PHP' started by baris22, Apr 15, 2008.

  1. #1
    Hello,

    What can i do to remove unwanted characters from form? I want to have numbers european letters and punctuation marks.

    I just want to remove everything else.

    Thanks
     
    baris22, Apr 15, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Here would be my method.

    Create an array of acceptable characters (e.g. 'a','b',...,'0','1',...)

    Preg_Split the input into single characters (see www.php.net/preg_split for sample code).

    Foreach() every character, and if in_array($character, $validcharacters) add it to a new, final string (i.e. $valid_input .= $character).

    I hope this helps,

    Jay
     
    jayshah, Apr 16, 2008 IP