16进制数据和字符串相互转换的函数
function String2Hex($string){ $hex=''; for ($i=0; $i < strlen($string); $i++){ $hex .= dechex(ord($string[$i])); } return $hex; } function Hex2String($hex){ $string=''; for ($i=0; $i < strlen($hex)-1; $i+=2){ $string .= chr(hexdec($hex[$i].$hex[$i+1])); } return $string; } // example: $hex = String2Hex("test sentence..."); // $hex contains 746573742073656e74656e63652e2e2e print Hex2String($hex); // outputs: test sentence...