Removing Illegal Characters

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

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).

Re: Removing Illegal Characters

*** matt wrote/escribió (Tue, 11 Jan 2005 21:41:50 +1000):
Quoted text here. Click to load it

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_replace('/[^0-9a-z ]+/i', '', $foo); // Code not tested
$foo=preg_replace('/[^\w\d\s]+/i', '', $foo); // Code not tested

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

Site Timeline