设为首页收藏本站淘宝杂货铺

从F到0 - From F to 0

 找回密码
 注册已关闭
搜索
查看: 1632|回复: 2
收起左侧

[PHP/ASP/JSP] PHP实现读写/生成 .bin 等任意格式二进制文件(自动转换成索引数组) 每个值范围(0~255)

[复制链接]
发表于 2019-3-6 17:47:55 | 显示全部楼层 |阅读模式
  1. <?php
  2. function array_file_get_contents($filename){        //参数1:文件名 返回索引数组
  3.         $file_data = file_get_contents($filename);
  4.         $return = array();
  5.         $len = strlen($file_data);
  6.                 for($i=0;$i<$len;$i++){
  7.                         array_push($return,ord($file_data[$i]));
  8.                 }
  9.         return $return;
  10. }

  11. function array_file_put_contents($filename,$file_data){        //参数1:文件名 参数2:索引数组 每个值范围(0~255) 返回 file_put_contents的结果
  12.         $len = sizeof($file_data);
  13.                 for($i=0;$i<$len;$i++){
  14.                         $file_data[$i]=chr($file_data[$i]&255);
  15.                 }
  16.         return file_put_contents($filename,$file_data);
  17. }

  18. array_file_put_contents("1.txt",array(72,101,108,108,111,32,87,111,114,108,100,33));
  19. print_r(array_file_get_contents("1.txt"));
  20. echo file_get_contents("1.txt");

  21. ?>
复制代码


您需要登录后才可以回帖 登录 | 注册已关闭

本版积分规则

QQ|手机版|Archiver|从F到0 ( 蒙ICP备17002595号-1 )
蒙公网安备15010402000325号

腾讯云安全认证

GMT+8, 2024-4-24 21:32 , Processed in 1.196069 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表