Hi StackOverflow Community,
Here is my question, how to convert php that has hex code into readable string ? On what I mean is all inside this 2 php code..
I had mixed content where besides hex and oct there was also normal chars.
So to update Sean's code above I added following
function decode_code($code)
{
return preg_replace_callback('@\\\(x)?([0-9a-f]{2,3})@',
function ($m) {
if ($m[1]) {
$hex = substr($m[2], 0, 2);
$unhex = chr(hexdec($hex));
if (strlen($m[2]) > 2) {
$unhex .= substr($m[2], 2);
}
return $unhex;
} else {
return chr(octdec($m[2]));
}
}, $code);
}
Example string
"\152\163\x6f\x6e\137d\x65\143\157\x64e"
Decoded output
"json_decode"