代码:
<?php
function str2hex($str){
return bin2hex($str);
}
function hex2str($hex){
$new = '';
for($i=0;$i<strlen($hex)-1;$i+=2){
$new .= chr(hexdec(substr($hex,$i,2)));
}
return $new;
}
$b = 'name=小明&sex=man';
$c = str2hex($b);
$d = hex2str($c);
echo "原始字符串:".$b.'<br/>';
echo "转16进制后:".$c.'<br/>';
echo "16进制转字符串:".$d.'<br/>';
输出:
原始字符串:name=小明&sex=man
转16进制后:6e616d653de5b08fe6988e267365783d6d616e
16进制转字符串:name=小明&sex=man