Re: string filtering

From: Date: Wed, 21 Jul 2004 00:55:49 +0000
Subject: Re: string filtering
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-191249@lists.php.net to get a copy of this message
C.F. Scheidecker Antunes wrote:
I need to filter some strings. They can only contain characters like a...z or A..Z and 0..9. Some strings have blank spaces, -,./?>,< characters that must be discarded. I wrote a function to check each and every character but I guess there must be something else more efficient. Any suggestions?
To get rid of them: $newstring = preg_replace('/[^0-9a-zA-Z]/','',$oldstring); To detect them: if(preg_match('/[^0-9a-zA-Z]/',$string)) { echo 'bad characters present'; } else { echo 'string okay'; } -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#191249) next »