我必须像十六进制字符一样写ascii数字(不是字母)。 一个字节必须包含2个数字(每个半字节一个), 假设这是我在文件中写入'0665879955443322'的字符串 这个结果06 65 87 99 55 44 33 22(8字节)我想要! (像打包格式) 我尝试这些做类似事情的例子
PHP
$a=0x06;
$b=0x65;
$c=0x87;
$txt = pack('CCC',$a,$b,$c) . "\x0A"; # Hex output is: 06 58 0A
$txt = "\x06" . "\x58" . "\x0C" . "\x0A";
# write to file to view with exadecimal editor
$bytes = file_put_contents('test',$txt);
echo "$bytes written<br>";
-----------
现在我的代码不会破坏!
$a="06";
$b="65";
$c="87";
//$txt = "\x06" . "\x58" . "\x0C" . "\x0A"; // this works
$txt = "\x" . $a" . "\x" . $b . "\" . $c . "\x0A"; // this not work !
$bytes = file_put_contents('test',$txt);
echo "$bytes written<br>";
---------
如何跟踪$ a b $ c就像是BYTES?
非常感谢