易截截图软件、单文件、免安装、纯绿色、仅160KB

php 字符串、文件转化成二进制流文件

$file1 = 'F:/46.gif';
$file2 = 'F:/test.txt';
$file3 = 'F:/47.gif';
$size = filesize($file1);
echo '文件大小为:'.$size;
echo "\n<br>转化为二进制 ...";
$content = file_get_contents($file1);
$content = bstr2bin($content);
$fp = fopen($file2, 'w');
fwrite($fp, $content);
fclose($fp);
$size2 = filesize($file2);
echo '转化成二进制后文件大小为:'.$size2;
$content = bin2bstr($content);
$fp = fopen($file3, 'w');
fwrite($fp, $content);
fclose($fp);
function bin2bstr($input)
// Convert a binary expression (e.g., "100111") into a binary-string
{
  if (!is_string($input)) return null; // Sanity check
  // Pack into a string
  $input = str_split($input, 4);
  $str = '';
  foreach ($input as $v)
  {
   $str .= base_convert($v, 2, 16);
  }
 
  $str =  pack('H*', $str);
 
  return $str;
}
function bstr2bin($input)
// Binary representation of a binary-string
{
  if (!is_string($input)) return null; // Sanity check
  // Unpack as a hexadecimal string
  $value = unpack('H*', $input);
 
  // Output binary representation
  $value = str_split($value[1], 1);
  $bin = '';
  foreach ($value as $v)
  {
   $b = str_pad(base_convert($v, 16, 2), 4, '0', STR_PAD_LEFT);
   
   $bin .= $b;
  }
 
  return $bin;
}


相关文档:

php 技术内幕学习2

1.php 数据类型:浮点型,字符串,整形,逻辑型
2.$a="test"; print($a); 在php.ini 中设置error_reporting=E_ALL 警告状态时,会有提示。此用于测试未定义的变量。可以使用isset()检测变量是否存在,unset清除变量(),常量定义define("a","test");定义的常量具有全局作用。define 无法定义对象的数据结构,不过可以先存储变量 ......

how to install apache, PHP and MySQL on Linux

how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE 9.2, 9.3, 10.0 & 10.1 operating systems, but most of the steps ought to be valid for all Linux-lik ......

php单引号和双引号的区别

本文转自http://xfs39.javaeye.com/blog/411508 感谢作者分享
php单引号和双引号的区别



    今天,有一新学PHP的网友问了茶农一个问题:“单引号和双引号的区别和用法?”,现将答案总结了下,写成这篇小短文。
" "双引号里面的字段会经过编译器 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号