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

From: Date: Wed, 18 Apr 2001 07:28:36 +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-49143@lists.php.net to get a copy of this message
Thanks for that help! Now I am getting an interesting error that I am not sure what to make of. Warning: REG_ERANGE in /home/httpd/www/worldvibe.org/digitall/edit_f.php on line 91 Here are lines surrounding 91: 89-> strtolower($f_loc_name); 90-> $f_loc_new = ""; 91-> $f_loc_new = ereg_replace("[^[_a-z0-9-\.]]", "", $f_loc_name); 92-> $f_loc_name = ""; 93-> $f_loc_name = $f_loc_new; I have tried tow other variations of line 91, and both of them do not seem to work the way I am hoping for. I have (since the last message, decided to remove the offending characters, rather than replace them with an underscore (hence the ""). Below is an example of what I am trying to accomplish: Test_File#()*#$.txt should be converted to test_file.txt TEST.file.#####.txt should be converted to sean.coyle..txt I am not all that great with regular expressions, so any help I can get on this is greatly appreciated! Kind Regards, Sean On 4/17/01 11:01 PM, in article DC017B079D81D411998C009027B7112A015ED111@EXC-TYO-01, "Maxim Maletsky" <maxim.maletsky@japaninc.net> wrote: > > $str = eregi_replace("[^[_a-z0-9-]]", '_', $str) > > would this 2-seconds written-in, non-tested scratch of code do the job? > > If not then something like this... > > eregi_replace() is what you are looking for. > > > > Sincerely, > > Maxim Maletsky > Founder, Chief Developer > PHPBeginner.com (Where PHP Begins) > maxim@phpbeginner.com > www.phpbeginner.com > > > > > -----Original Message----- > From: Sean Coyle [mailto:uid0@worldvibe.org] > Sent: Wednesday, April 18, 2001 2:23 PM > To: php-general@lists.php.net > Subject: [PHP] Is it possible to parse a variable by character? > > > 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. > > Any ideas on how I can go about doing something like this? > > BTW: (Some background info) I examined the average validate e-mail idea, > however, rather than reject the string, I would like to be able to 'replace' > the offending character. > > Thanks in advance, > > Sean >

« previous php.general (#49143) next »