0

I've run into an issue converting hexadecimal encoding into a string when the hexidecimal character has 3 characters (rather than the usual 2).

I current use the following function which has been working fine:

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

I'm aware I can also use:

pack("H*", $hex);

Example characters which don't convert: ă ţ which are represented as 103 163 in hexadecimal. Interestingly websites like: https://codebeautify.org/string-hex-converter don't recognise their own conversion of these characters.

Example hexadecimal:

7061726f6c65692070656e74727520636f6e74756c2064756d6e6561766f61737472103206120666f737420696e69163696174103

Expected output:

parolei pentru contul dumneavoastră a fost iniţiată

AdrianH
  • 1
  • 1

0 Answers0