Re: Is it possible to parse a variable by character?

From: Date: Wed, 18 Apr 2001 12:07:31 +0000
Subject: Re: Is it possible to parse a variable by character?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49192@lists.php.net to get a copy of this message
On Wednesday 18 April 2001 07:22, you wrote: > Hey there guys, > > This may seem like a dumb question, but I have to ask it anyway. > > I have a form in one of my php based scripts that allows for file > uploads. I recently noticed a potential issue if people upload files > containing anything else but the standard characters > ([_a-z0-9-]+(\.[_a-z0-9-]). > > I am not sure if this can be done, but what I need to do is parse > this variable (lets call it $file_name) by character looking for > anything save letters a-z (A-Z) and numbers 0-9. Any arrangements of > numbers, letters and full stops (.) are to be permitted, and if any > character does not meet those specifications, that single character > should be converted to an underscore. $Input = preg_replace ('/[^\w.-]/', '_', $$Input); I assumed that you also want to allow "minus" signs. See the manual section on the regular expression functions (Perl-compatible) for an explanation -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) AAAAA - American Association Against Acronym Abuse

« previous php.general (#49192) next »