【发布时间】:2014-05-26 02:12:51
【问题描述】:
我正在尝试编辑文件的字节。更像是一个十六进制查看器/编辑器。 例如:
//Adding the file bytes to array (byte array)
$bytes = str_split(file_get_contents("test.file")); //It can be any file. like jpg,png, exe, jar...
现在我只想编辑 5 个字节并将它们更改为一些字符值。 例如:
//Adding the file bytes to an array (byte array)
$bytes = str_split(file_get_contents("test.file")); //It can be any file. like jpg,png, exe,jar...
$string = "hello";
$bytes[5] = $string[0];
$bytes[6] = $string[1];
$bytes[7] = $string[3];
$bytes[8] = $string[4];
file_put_contents("edited.file", $bytes);
但它不起作用...我需要先将 $string 的字母转换为字节,然后编辑字节数组的特定字节($bytes),而不会损坏文件。
我曾尝试使用 unpack()、pack() 函数,但我无法使其工作... 我也尝试过 ord() 函数,但随后将它们保存为整数,但我想保存字符串的字节。
【问题讨论】:
标签: php arrays string hex byte