Open In App

PHP mb_ord() Function

The m_ord() is an inbuilt function in PHP that returns the Unicode code point for the specific character.

Syntax:



mb_ord(string $string, ?string $encoding = null): int|false

Parameters: This function has two parameters:

Return value: This function returns the first character Unicode if the function is successfully executed otherwise it will return “false”.



Example 1: The following code demonstrates the mb_ord() function.




<?php    
$string = '©';
$code_point = mb_ord($string, 'ISO-8859-1');
echo $code_point;    
?>

Output:

194

Example 2: The following code demonstrates the mb_ord() function.




<?php    
$word = 'Hello';
$code_point = mb_ord($word, 'UTF-8');
      
if ($code_point === 72) {
    echo "The first character in the word is 'H'.";
}
else {
    echo "The first character in the word is not 'H'.";
}    
  
?>

Output:

The first character in the word is 'H'.

Reference: https://www.php.net/manual/en/function.mb-ord.php

Article Tags :