Removing Illegal Characters

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-11-2005
matt
 
Posts: n/a
Default 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
Reply With Quote
  #2 (permalink)  
Old 01-11-2005
Alvaro G Vicario
 
Posts: n/a
Default Re: Removing Illegal Characters

*** 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
--
Reply With Quote
  #3 (permalink)  
Old 01-11-2005
Claudius
 
Posts: n/a
Default 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).

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:54 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0