Computer >> Computer tutorials >  >> Programming >> PHP

PHP – How to get the Unicode point value of a given character?


In PHP, we can use the mb_ord() function to get the Unicode code point value of a given character. This function is supported in PHP 7 or higher versions. The mb_ord() function complements the mc_chr() function.

Syntax

int mb_ord($str_string, $str_encoding)

Parameters

mb_ord() accepts the following two parameters −

  • $str_string − This parameter is used for the string.

  • $str_encoding − This is the character encoding parameter. If it is absent or NULL, then we can use the internal encoding value.

Return Values

mb_ord() returns the Unicode point value for the first character from the given string. It will return False on failure.

Example

<?php
   echo "Get the numeric value of character \n";
   var_dump(mb_ord("B", "UTF-8"));
   var_dump(mb_ord("d", "UTF-8"));
   var_dump(mb_ord("\x80", "ISO-8859-2"));
   var_dump(mb_ord("\x80", "Windows-1251"));
?>

Output

It will produce the following output −

Get the numeric value of characters
int(66)
int(100)
int(128)
int(1026)