1

我在字符串变量中有以下十六进制格式:

$str = "0dae28";

我想通过套接字接口将上述内容作为十六进制值(例如 0x0dae28)发送:

socket_write($spawn,$output,strlen($output));

因此,我很好奇我应该怎么做才能以$str十六进制格式的数据发送。$output$output

非常感谢任何输入。谢谢!

4

1 回答 1

3

使用 PHP 的hex2bin()函数:

Example #1 hex2bin() 例子

<?php
$hex = hex2bin("6578616d706c65206865782064617461");
var_dump($hex);
?>
上面的示例将输出类似于:

string(16) "示例十六进制数据"

因此,在您的情况下:

$output = hex2bin($str);
于 2012-05-29T08:53:23.507 回答