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ă

3
  • 2
    Please clarify what your input data is, and what the exact expected result. Commented Feb 10, 2023 at 10:44
  • 1
    stackoverflow.com/a/50056467/4248328 Commented Feb 10, 2023 at 10:56
  • Updated with an example input Commented Feb 11, 2023 at 10:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.