Check for character(s) representing a hexadecimal digit with ctype_xdigit in PHP

Description

The following code shows how to check for character(s) representing a hexadecimal digit with ctype_xdigit.

Example


/*from  w w  w.  j ava  2 s. co  m*/
<?php
$strings = array('QQQQQ10WWWW99', 'QQQQ1012', 'ab12bc99');
foreach ($strings as $testcase) {
    if (ctype_xdigit($testcase)) {
        echo "The string $testcase consists of all hexadecimal digits.\n";
    } else {
        echo "The string $testcase does not consist of all hexadecimal digits.\n";
    }
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone