note 53613 deleted from function.preg-match by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:23:05 +0000 |
| Subject: | note 53613 deleted from function.preg-match by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127602@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at m-bread dot com
----
If you want to get all the text characters from a string, possibly entered by a user, and filter out
all the non alpha-numeric characters (perhaps to make an ID to enter user-submitted details into a
database record), then you can use the function below. It returns a string of only the alpha-numeric
characters from the input string (all in lower case), with all other chracters removed.
<?php
function removeNonAN($string){
preg_match_all('/(?:([a-z]+)|.)/i', $string, $matches);
return strtolower(implode('', $matches[1]));
};//EoFn removeNonAN
?>
It took me quite a while tocome up with this regular expression. I hope it saves someone else that
time.