如何将文本转换为utf32编码

时间:2019-07-16 06:38:35

标签: php encoding character-encoding

我需要像这样将文本转换为utf32编码。

所以我如何在php中将字符串转换为utf32编码,我尝试对方法进行编码但不起作用。

String: test
Output: 00000074000000650000007300000074

mb_convert_encode("testt",'HTML-ENTITIES','UTF-8'); 

stri_enc_toutf32(str)


1 个答案:

答案 0 :(得分:1)

$out = mb_convert_encoding($in, 'UTF-32', 'UTF-8');

对输出中的特定字节顺序使用UTF-32BEUTF-32LE(请参见supported character encodings)。

注意,第三个参数是源字符串编码。因此,请确保它与实际使用的编码匹配。

UPD 如果要使用十六进制文本字符串,则可以使用bin2hex将二进制UTF-32字符串转换为文本:

$text = bin2hex ($out);

示例:

  $in = "test";

  $out = mb_convert_encoding($in, 'UTF-32', 'UTF-8');
  $text =  bin2hex ($out) ;

  print ($text); // 00000074000000650000007300000074