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
/* @author: zhuyubing@gmail.com */
class Template{
var $code;
function Template($template){
$this->code = implode('', @file($tem ......
本文转自http://xfs39.javaeye.com/blog/411508 感谢作者分享
php单引号和双引号的区别
今天,有一新学PHP的网友问了茶农一个问题:“单引号和双引号的区别和用法?”,现将答案总结了下,写成这篇小短文。
" "双引号里面的字段会经过编译器 ......
<?PHP
/**
* patServer
* PHP socket server base class
* Events that can be handled:
* * onStart
* * onConnect
* * onConnectionRefused
* * onClose
* * onShutdown
* * onReceiveData
*
* @version 1.1
* @author &n ......
问题一:cacti如法正常登录,没有报PHP程序错误
解决过程解决过程:开启PHP报错显示(在调试时,一直卡在这儿,由于是服务器上,没有开启报错程序)display_errors = On
发现报Warning: session_start() [ ......
以动手实践为荣 , 以只看不练为耻;
以打印日志为荣 , 以单步跟踪为耻;
以空格缩进为荣 , 以制表缩进为耻;
以单元测试为荣 , 以人工测试为耻;
以模块复用为荣 , 以复制粘贴为耻;
以多态应用为荣 , 以分支判断为耻;
以Pythonic为荣 , 以冗余拖沓为耻;
以总结分享为荣 , 以跪求其解为耻; ......