php转换字符串十六进制不编码

I receive data like this:

$string = "\x01\x03\x08\xc0";

From this variable how to output (with echo) the same value?

For example on python, when I type:

$ print [string]

I get this

["\x01\x03\x08\xc0"]

Note: Without do $string = '\x01\x03\x08\xc0' because I uses a server who receives data and the string variable is the data.

Can someone can help me?

when php interpreter reach the line:

$string = "\x01\x03\x08\xc0";

it automatically parse string between double quotes. so you can not get real string. but if you can guarantee that response you get is a valid hex, use function bin2hex(). in that case you can convert result of that function to what you want. something like:

$str = bin2hex($hex);
$real_str = '';
for($i=0; $i<strlen($str); $i+=2){
    $real_str .= '\\x'.$str[$i].$str[$i+1];
 }
 echo $real_str;