//字符串转换成16进制
function str2hex($str){
$hex = '';
for($i=0,$length=mb_strlen($str); $i<$length; $i++){
$hex .= dechex(ord($str{$i}));
}
return $hex;
}
//16进制转换成字符串
function hex2str($hex){
$str = '';
$arr = str_split($hex, 2);
foreach($arr as $bit){
$str .= chr(hexdec($bit));
}
return $str;
}
function test(){
//utf8字符测试
$str = '中文';
echo mb_strlen($str);
echo '';
$hex = str2hex($str);
echo $hex;
echo '';
$dec = hex2str($hex);
echo $dec;
echo "";
echo "