如何仅将阿拉伯字符的编码从 utf8 更改为 big-endian 以通过 SMS 服务发送 SMS 消息?此代码不起作用。mb_convert_encoding($str, "UCS-2BE", "auto");结果应该是 这样的
1 回答

天涯尽头无女友
TA贡献1831条经验 获得超9个赞
您必须执行以下操作:
检查编码和阿拉伯字符的存在。你可以这样做:
//$text - string that you need to convert
if (mb_detect_encoding ($text) == "UTF-8" && mb_ereg('[\x{0600}-\x{06FF}]', $text)) {
...
}
将字符串转换为 USC-2BE 编码。您可以使用iconv函数
iconv("UTF-8", "UCS-2BE", $text)
然后解压缩为所需的格式(H*hex - 在你的情况下)并转换为大写:
if (mb_detect_encoding ($text) == "UTF-8" && self::isArabic($text)) {
$arr = unpack("H*hex", @iconv("UTF-8", "UCS-2BE", $text));
$text = strtoupper($arr["hex"]);
}
而已。它应该工作。
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报
0/150
提交
取消