我在PHP的这2种类型之间进行转换时遇到问题。这是我在谷歌搜索的代码
function strToHex($string){
$hex='';
for ($i=0; $i < strlen($string); $i++){
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function hexToStr($hex){
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2){
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
我检查了一下,并在使用XOR加密时发现了这一点。
我有字符串"this is the test",在与键进行XOR之后,结果在string中↕↑↔§P↔§P ♫§T↕§↕。之后,我尝试通过功能strToHex()将其转换为十六进制,并得到了这些12181d15501d15500e15541215712。然后,我使用功能hexToStr()进行了测试,然后得到了↕↑↔§P↔§P♫§T↕§q。那么,该怎么办才能解决这个问题呢?转换这2个样式值时为什么会出错?
子衿沉夜
守候你守候我