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

From: Date: Wed, 18 Apr 2001 10:25:07 +0000
Subject: Re: Is it possible to parse a variable by character?
References: 1  Groups: php.lang 
Request: Send a blank email to php-lang+get-143@lists.php.net to get a copy of this message
Someone mentioned $str[offset] will be depreciated in the future in php-general. $str{offset} can be used to access char in string. I wonder why this is not in the manual some where obvious place. -- Yasuo Ohgaki ""Yasuo Ohgaki"" <yohgaki@hotmail.com> wrote in message news:OE35Xjaf3mOV9e8L25s00004a67@hotmail.com... > It does not allow cross post to news server.... Posting again. > > [Cross post to php-lang/php-general] > Regular expression functions can do the job and already have reply. > > Answer for the original question: How to access string by character. > > I'm not sure if accessing string as array is going to be depreciated or not. > (Or is it already depreciated???) > But you could do > > $str = 'abc'; > for ($i = 0; $i < strlen($i); $i++) { > echo $str[$i]; > } > > It prints characters in string one by one. > > I also not sure behavior of following code is defined or not. > (It's used to be undefined. You probably should not rely on this.) > > $str = 'abc'; > $str[0] = 'X'; > > You may get > $str = 'Xbc' or $str[0] = 'X'. > > Anyone knows current status on this??? > > Regards, > -- > Yasuo Ohgaki > > > "Sean Coyle" <uid0@worldvibe.org> wrote in message > news:B70272AA.D54%uid0@worldvibe.org... > > 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 > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > -- > PHP Language Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-lang-unsubscribe@lists.php.net > For additional commands, e-mail: php-lang-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.lang (#143) next »