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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to