Answer the question
In order to leave comments, you need to log in
php: how to decode python hex string?
Hello.
I get a line like this from python code by exec:
\\xd0\\xa0\\xd1\\x83\\xd1\\x81\\xd1\\x81\\xd0\\xba\\xd0\\xb8\\xd0\\xb9
Answer the question
In order to leave comments, you need to log in
$input = '\\xd0\\xa0\\xd1\\x83\\xd1\\x81\\xd1\\x81\\xd0\\xba\\xd0\\xb8\\xd0\\xb9';
$input2 = "\xd0\xa0\xd1\x83\xd1\x81\xd1\x81\xd0\xba\xd0\xb8\xd0\xb9";
$output = preg_replace_callback(
'/\\\\x([a-f0-9]{2})/',
function($match) {
return pack('H*', $match[1]);
},
$input
);
var_dump($output, $input2 === $output);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question