This is a discussion on Removing Illegal Characters within the PHP Language forums, part of the PHP Programming Forums category; I have an upload script for a photo and a caption. It all goes pear shaped when I upload a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
*** matt wrote/escribió (Tue, 11 Jan 2005 21:41:50 +1000):
> 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??? 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 -- |
|
|||
|
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). |