How to Retrieve Characters from Unicode Code Points in PHP?

DDD
Release: 2024-10-26 10:54:02
Original
338 people have browsed it

How to Retrieve Characters from Unicode Code Points in PHP?

Getting Characters from Unicode Code Points in PHP

PHP offers several functions to manipulate Unicode characters represented by their code points. One common scenario involves retrieving the character associated with a specific Unicode code point.

Solution

PHP provides helper functions to decode HTML entities and convert between UTF-8 and UCS-4BE encodings. Utilizing these functions, we can retrieve characters from Unicode code points as follows:

<code class="php">header('Content-Encoding: UTF-8');

function mb_html_entity_decode($string)
{
    // ... Encoding conversion and decoding logic
}

function mb_ord($string)
{
    // ... UTF-8 to UCS-4BE conversion and unpacking
}

function mb_chr($string)
{
    // ... HTML entity encoding and decoding
}

// Example: Getting the character for U+010F

$codePoint = hexdec('010F');
print mb_chr($codePoint); // Outputs ó</code>
Copy after login

Alternatively:

<code class="php">$codePoint = 243;
print mb_ord('ó'); // Outputs 243
print mb_chr(243); // Outputs ó</code>
Copy after login

The above is the detailed content of How to Retrieve 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
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!