note 53612 added to function.preg-match-all

From: Date: Tue, 07 Jun 2005 12:40:03 +0000
Subject: note 53612 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-90054@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53612 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53612&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53612&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53612&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53612&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53612&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53612&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90054) next »