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


基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php中的PDF导出 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01