1. 问答
  2. 问答详情

php 读取一个文件,保存为16进制的数字

php 读取一个文件,保存为16进制的数字

1个回答

0

采纳

文件里面的每一个字节的ascii码转成16进制就可以了,如:

$content = file_get_contents("file");
$hex = "";
for($i=0;$i<=strlen($content);$i++){
   $asc = ord(substr($content,$i,1));
   $hex .= dechex($asc);
}
file_put_contents("newfile",$hex);

撰写答案

验证码
点击刷新