Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
PHP Function ctype_digit()
Syntax
Definition and Usage
Checks if all of the characters in the provided string, text, are numerical. It checks only 1...9
Paramters
Parameter | Description |
text | Required. The tested string. |
Return Value
Returns TRUE if every character in text is a decimal digit, FALSE otherwise.
Example
Try out following example:
<?php
$strings = array('122.50', '1004', 'foo!#$bar');
foreach ($strings as $testcase) {
if (ctype_digit($testcase)) {
echo "$testcase consists of all digits.<br />";
} else {
echo "$testcase does not have all digits.<br />";
}
}
?>
|
This will produce following result:
122.50 does not have all digits
1004 consists of all digits
foo!#$bar does not have all digits
|
|
|
|