首页 > 代码库 > 中文编码与解码

中文编码与解码

<?phpfunction hex_encode($s) {    $s = iconv(‘UTF-8‘, ‘GBK‘, $s);    return preg_replace(‘/(.)/es‘, "str_pad(dechex(ord(‘\\1‘)),2,‘0‘,STR_PAD_LEFT)", $s);}function hex_decode($s) {    return preg_replace(‘/(\w{2})/e‘, "chr(hexdec(‘\\1‘))", $s);}var_dump(hex_encode("李照耀"));var_dump(hex_decode("c0eed5d5d2ab"));?>

技术分享

中文编码与解码