4

如何把 utf8 汉字转 16 进制格式

 2 years ago
source link: https://www.v2ex.com/t/811595
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

如何把 utf8 汉字转 16 进制格式

  cs5117155 · 1 天前 · 729 次点击
echo Utf8ToHex("5g");
function Utf8ToHex($str){
    $str = rawurlencode($str);
    $arr = explode('%',$str);
    $Hex = implode('',$arr);
    return $Hex;
}

我这个函数如果是汉字的情况它就是正确,如果是数字+英文,他就不行了。 比如输入5g得到 16 进制是35 67; 输入123456得到 16 进制是31 32 33 34 35 36; 网上找了几个 php 语言方法都不太好使


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK