Removing Illegal Characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matt

    Removing Illegal Characters

    I have an upload script for a photo and a caption. It all goes pear
    shaped when I upload a character like ' " or / \ |
    Is there anyway I can parse through the filename when submitting the
    form and remove any illegal characters like this???

    Thanks in advance
    Matt
  • Alvaro G Vicario

    #2
    Re: Removing Illegal Characters

    *** matt wrote/escribió (Tue, 11 Jan 2005 21:41:50 +1000):[color=blue]
    > I have an upload script for a photo and a caption. It all goes pear
    > shaped when I upload a character like ' " or / \ |
    > Is there anyway I can parse through the filename when submitting the
    > form and remove any illegal characters like this???[/color]

    Usage: mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )
    Purpose: Perform a regular expression search and replace
    Availability: PHP 3>= 3.0.9, PHP 4

    Rather than removing a set of invalid chars, I suggest you remove
    everything except a set of valid chars.

    $foo=preg_repla ce('/[^0-9a-z ]+/i', '', $foo); // Code not tested
    $foo=preg_repla ce('/[^\w\d\s]+/i', '', $foo); // Code not tested


    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Thank you for not e-mailing me your questions
    --

    Comment

    • Claudius

      #3
      Re: Removing Illegal Characters

      I think you can also use the addslashes() and stripslashes() function.

      string addslashes ( string str)
      Returns a string with backslashes before characters that need to be
      quoted in database queries etc. These characters are single quote ('),
      double quote ("), backslash (\) and NUL (the NULL byte).

      Comment

      Working...