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 字符


基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01