How to Obtain Characters from Unicode Code Points in PHP?

Barbara Streisand
Release: 2024-10-26 14:36:30
Original
288 people have browsed it

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>
Copy after login

mb_chr()

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

Code:

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

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!