Unicode character in PHP string(PHP 字符串中的 Unicode 字符)
问题描述
这个问题看起来很简单,但我一直没能找到答案.
This question looks embarrassingly simple, but I haven't been able to find an answer.
与以下 C# 代码行等效的 PHP 是什么?
What is the PHP equivalent to the following C# line of code?
string str = "u1000";
此示例使用单个 Unicode 字符创建一个字符串,该字符的Unicode 数值"为是 1000
十六进制(4096
十进制).
This sample creates a string with a single Unicode character whose "Unicode numeric value" is 1000
in hexadecimal (4096
in decimal).
也就是说,在 PHP 中,如何使用单个 Unicode 字符创建一个字符串,该字符的Unicode 数值"为知道吗?
That is, in PHP, how can I create a string with a single Unicode character whose "Unicode numeric value" is known?
推荐答案
因为 JSON 直接支持 uxxxx
语法我首先想到的是:
Because JSON directly supports the uxxxx
syntax the first thing that comes into my mind is:
$unicodeChar = 'u1000';
echo json_decode('"'.$unicodeChar.'"');
另一种选择是使用 mb_convert_encoding()
echo mb_convert_encoding('က', 'UTF-8', 'HTML-ENTITIES');
或者利用 UTF-16BE(大端)和 Unicode 代码点之间的直接映射:
or make use of the direct mapping between UTF-16BE (big endian) and the Unicode codepoint:
echo mb_convert_encoding("x10x00", 'UTF-8', 'UTF-16BE');
这篇关于PHP 字符串中的 Unicode 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 字符串中的 Unicode 字符


- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01