note 53612 deleted from function.preg-match-all by colder
| From: | colder@php.net | Date: | Mon, 16 Apr 2007 16:58:20 +0000 |
| Subject: | note 53612 deleted from function.preg-match-all by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125461@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at swirldrop dot com
----
If you want to get al 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 getText($string){
preg_match_all('/(?:([a-z]+)|.)/i', $string, $matches);
return strtolower(implode('', $matches[1]));
};//EoFn getText
?>
It took me quite a while tocome up with this regular expression. I hope it saves someone else that
time.