PHP convert string to hex and hex to string
<p>I got the problem when convert between this 2 type in PHP. This is the code I searched in google</p>

<pre><code>function strToHex($string){
    $hex='';
    for ($i=0; $i &lt; strlen($string); $i++){
        $hex .= dechex(ord($string[$i]));
    }
    return $hex;
}


function hexToStr($hex){
    $string='';
    for ($i=0; $i &lt; strlen($hex)-1; $i+=2){
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
}
</code></pre>

<p>I check it and found out this when I use XOR to encrypt.</p>

<p>I have the string <code>"this is the test"</code>, after XOR with a key, I have the result in string <code>↕↑↔§P↔§P ♫§T↕§↕</code>. After that, I tried to convert it to hex by function strToHex() and I got these <code>12181d15501d15500e15541215712</code>. Then, I tested with the function hexToStr() and I have <code>↕↑↔§P↔§P♫§T↕§q</code>. So, what should I do to solve this problem? Why does it wrong when I convert this 2 style value?</p>
