Home  >  Article  >  Backend Development  >  How to Obtain Characters from Unicode Code Points in PHP?

How to Obtain Characters from Unicode Code Points in PHP?

Barbara Streisand
Barbara StreisandOriginal
2024-10-26 14:36:30289browse

How to Obtain Characters from Unicode Code Points in PHP?

Obtaining Characters from Unicode Code Points in PHP

In PHP, there are multiple ways to retrieve characters from their respective Unicode code points. This article delves into these methods, providing code examples for each.

Methods:

mb_ord()

  • This function returns the numeric Unicode value of a given character.

Code:

<code class="php">$unicodeCodePoint = 0x010F;
$character = mb_ord('ó');</code>

mb_chr()

  • This function converts a Unicode code point to its corresponding character.

Code:

<code class="php">$unicodeCodePoint = 243;
$character = mb_chr($unicodeCodePoint);</code>

mb_html_entity_decode()

  • This function converts a numeric character reference (NCR) into its corresponding character. NCRs are hexadecimal representations of Unicode code points.

Code:

<code class="php">$unicodeCodePoint = '010F';
$character = mb_html_entity_decode('&amp;#' . $unicodeCodePoint . ';');</code>

var_dump()

  • This function can be used to display the numeric value of a Unicode code point in hexadecimal format.

Code:

<code class="php">$unicodeCodePoint = '010F';
var_dump(hexdec($unicodeCodePoint));</code>

The above is the detailed content of How to Obtain Characters from Unicode Code Points in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn