note 55562 deleted from ref.ctype by colder
| From: | colder@php.net | Date: | Fri, 23 Feb 2007 12:32:42 +0000 |
| Subject: | note 55562 deleted from ref.ctype by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123754@lists.php.net to get a copy of this message | ||
Note Submitter: Gregory Boshoff
----
As noted above unfortunately many PHP developers are seemingly unaware of these functions and are
still using less efficient equivalents.
Use the ctype functions for input type vaildation.
Example wrapper function:
function detect_type($str, $type_req = ''){
$type = array();
(ctype_alnum($str) === TRUE) ? ($type = 'alnum') : FALSE;
(ctype_digit($str) === TRUE) ? ($type = 'digit') : FALSE;
(ctype_alpha($str) === TRUE) ? ($type = 'alpha') : FALSE;
return ($type === $type_req) ? TRUE : FALSE;
} // end fun
$str = 'AlphaString';
$type_req = 'alpha';
// Returns TRUE if the string is of the required type
echo detect_type($str, $type_req);