PHP | ctype_xdigit() Function
The ctype_xdigit() function in PHP used to check each and every character of string/text are hexadecimal digit or not. It return TRUE if all characters are hexadecimal otherwise return FALSE .
Syntax :
ctype_xdigit(string text)
Parameters Used:
- text : It is mandatory parameter which specifies the tested string.
Return Values:
It returns TRUE if all characters of the string are hexadecimal otherwise return FALSE.
Examples:
Input : ABCDEF0123
Output : Yes
Input : GFG2018
Output : No
Note : It checking decimal digit or a character from [A-F, a-f].
Below programs illustrate the ctype_xdigit() function.
Program: 1
<?php
$string = 'ABab012' ;
if ( ctype_xdigit( $string )) {
echo "Yes \n" ;
} else {
echo "No \n" ;
}
?>
|
Program: 2
Take one more example ctype_xdigit() function to check how it work when input contains uppercase lowercase and symbol character by using input as array of string.
<?php
$strings = array (
'ABCDEF' ,
'abcdef' ,
'0123456789X' ,
'0123456789' ,
'Gg@(*&)' ,
'GFG'
);
foreach ( $strings as $test ) {
if (ctype_xdigit( $test )) {
echo "Yes \n" ;
} else {
echo "No \n" ;
}
}
?>
|
Output:
Yes
Yes
No
Yes
No
No
References : http://php.net/manual/en/function.ctype-xdigit.php
Last Updated :
05 Jun, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...