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;
}
相关文档:
概述
1.PHP 是什么?
PHP 是服务器端解释的脚本语言,它是目前最流行的 web 编程语言之一。 在一个 HTML 页面中可以嵌入PHP代码,这些代码在每次页面访问时执行。PHP 代码将在 Web 服务器中被解释并且生成 HTML或者访问者看到其他输出结果。
2.My SQL 是什么?
My SQL 是基于 SQL 的完 ......
<?php
/* @author: zhuyubing@gmail.com */
class Template{
var $code;
function Template($template){
$this->code = implode('', @file($tem ......
弄了半天, PHP 终于能调用我的C# dll 了.
该死的,我对C# COM注册一向不了解, PHP 文档上只给PHP那部分内容,没告诉我怎么弄dll
我还傻兮兮的用 Regsvr32 注册那个c# dll.
背景:
Windows xp sp3 ; apache 2.2.14 ; php 5.2.12 ;
VS2010 beta ;
语言:
PHP5 , C#
C#部分:
创建一个 C# Class Library . (dll) ......
转自:http://www.phpq.net
准备:
1、一台安装好的 Windows 2003 服务器,并且已经安装了 IIS 6。
2、下载 windows 版的 PHP 二进制压缩包。
安装:
解压缩 PHP 二进制压缩包到 C:\php 目录下(这里假设 C: 盘是系统盘,即安装了Windows 系统的盘,如果系统盘是 D:
盘,则解压缩到 D:\php 目录下,以此类推,下 ......