UTF-8 十六进制代码到 Unicode
UTF-8 Hex code to Unicode
假设我有俄语西里尔字母字符串“журнал”,它有以下十六进制代码:
d0 b6 d1 83 d1 80 d0 bd d0 b0 d0 bb
但是如何将此十六进制代码转换回人类可读的西里尔字符串 in PHP?我检查了很多来源,到目前为止没有任何效果。
你可以使用这个:
function hex2str($hex) {
$str = '';
for($i = 0; $i < strlen($hex); $i += 2) {
$str .= chr(hexdec(substr($hex, $i, 2)));
}
return $str;
}
$string = preg_replace('/\s+/', '', 'd0 b6 d1 83 d1 80 d0 bd d0 b0 d0 bb');
echo hex2str($string);
假设我有俄语西里尔字母字符串“журнал”,它有以下十六进制代码:
d0 b6 d1 83 d1 80 d0 bd d0 b0 d0 bb
但是如何将此十六进制代码转换回人类可读的西里尔字符串 in PHP?我检查了很多来源,到目前为止没有任何效果。
你可以使用这个:
function hex2str($hex) {
$str = '';
for($i = 0; $i < strlen($hex); $i += 2) {
$str .= chr(hexdec(substr($hex, $i, 2)));
}
return $str;
}
$string = preg_replace('/\s+/', '', 'd0 b6 d1 83 d1 80 d0 bd d0 b0 d0 bb');
echo hex2str($string);