如何将编码从 utf8 更改为 big endian

How can I change the encoding from utf8 to big endian

如何将编码从utf8更改为仅阿拉伯字符的big-endian编码以通过SMS服务发送SMS消息?此代码不起作用。

mb_convert_encoding($str, "UCS-2BE", "auto");

结果应该是这样的 this

您必须执行以下操作:

  1. 检查编码和是否存在阿拉伯字符。你可以这样做:

     //$text - string that you need to convert
    
     if (mb_detect_encoding ($text) == "UTF-8" && mb_ereg('[\x{0600}-\x{06FF}]', $text)) {
                ...
     }
    
  2. 将字符串转换为 USC-2BE encoding.You 可以使用 iconv 函数

    iconv("UTF-8", "UCS-2BE", $text)
    
  3. 然后unpack to needed format (H*hex - in your case) and convert to uppercase:

    if (mb_detect_encoding ($text) == "UTF-8" && self::isArabic($text)) {
                $arr = unpack("H*hex", @iconv("UTF-8", "UCS-2BE", $text));
                $text = strtoupper($arr["hex"]);
    }
    

就是这样。它应该有效。