php – 将十六进制数据写入文件
发布时间:2020-12-13 22:03:31 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试一段代码. ?php$tmp = ord('F'); //gives the decimal value of character F (equals 70)$tmp = $tmp - 55; //gives 15 - decimal equivalent of 0x0F$tmp = dechex($tmp); // converts 15 to 0x0F$fp = fopen("testing.data","wb+");fwrite($fp,$
我正在尝试一段代码.
<?php $tmp = ord('F'); //gives the decimal value of character F (equals 70) $tmp = $tmp - 55; //gives 15 - decimal equivalent of 0x0F $tmp = dechex($tmp); // converts 15 to 0x0F $fp = fopen("testing.data","wb+"); fwrite($fp,$tmp); fclose($fp); ?> 当我在十六进制编辑器中打开名为testing.data的文件时,我看到写入了2个字节. 2个字节是0x36和0x33. 解决方法
如果要将字节0x0f写入文件,只需使用该ASCII代码编写字符即可.你实际上想要撤消ord,反向函数是
chr :
<?php $tmp = ord('F'); //gives the decimal value of character F (equals 70) $tmp = $tmp - 55; //gives 15 - decimal equivalent of 0x0F $tmp = chr($tmp); // converts 15 to a character $fp = fopen("testing.data",$tmp); fclose($fp); ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |