PHP | IntlChar::isxdigit() Function

The IntlChar::isxdigit() function is an inbuilt function in PHP which is used to check whether the given input character is a hexadecimal digit or not. It is TRUE for decimal digit numbers (0 – 9), Latin letters (a – f) and (A – F) in both ASCII and Fullwidth ASCII (Letters with codepoint \u{0041} to \u{0046}, \u{0061} to \u{0066}, \u{FF21} to \u{FF26} and \u{FF41} to \u{FF46}).

Syntax:

bool IntlChar::isxdigit( $codepoint )

Paramters: This function accepts a single parameter $codepoint which is mandotary. The input parameter is an integer values or character, which is encoded as a UTF-8 string.



Return Value: If $codepoint is a hexadecimal digit then it returns True, otherwise return False.

Below programs illustrate the IntlChar::isxdigit() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP code to illustrate IntlChar::isxdigit()
// function
    
// Input data is digit type 0-9
var_dump(IntlChar::isxdigit("0"));
var_dump(IntlChar::isxdigit("9"));
var_dump(IntlChar::isxdigit("10"));
    
// Input data is character type
var_dump(IntlChar::isxdigit("A"));
var_dump(IntlChar::isxdigit("a"));
var_dump(IntlChar::isxdigit("F"));
var_dump(IntlChar::isxdigit("f"));
var_dump(IntlChar::isxdigit("G"));
var_dump(IntlChar::isxdigit("g"));
  
// Input data is FULL ASCII
var_dump(IntlChar::isxdigit("\u{0041}"));
var_dump(IntlChar::isxdigit("\u{0046}"));
var_dump(IntlChar::isxdigit("\u{0047}"));
  
?>

chevron_right


Output:

bool(true) 
bool(true) 
NULL 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(false) 
bool(false) 
bool(true) 
bool(true) 
bool(false) 

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP code to illustrate isxdigit()
       
// Declare an array $arr
$arr = array("0", "9", "a", "A", "f", "\u{0041}"
      "\u{0066}", "\u{0067}", "G", "10", "Geeks");
      
// Loop run for every array element
foreach ($arr as $val){
          
    // Check each element as code point data
    var_dump(IntlChar::isxdigit($val));
}
?>

chevron_right


Output:

bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(false) 
bool(false) 
NULL 
NULL 

Note: IntlChar::isxdigit() is equivalent to IntlChar::digit($codepoint, 16) >= 0.

Related Articles:

Reference: http://php.net/manual/en/intlchar.isxdigit.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.