By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,334 Members | 2,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,334 IT Pros & Developers. It's quick & easy.

Removing Illegal Characters

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
*** 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
--
Jul 17 '05 #2

P: n/a
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).

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.