//author: selfimpr
//blog: http://blog.csdn.net/lgg201
//mail: [email protected]
//EF BB BF这三个字节称为bom头
function hasbom(&$content) {
$firstline = $content[0];
return ord(substr($firstline, 0, 1)) === 0xEF
and ord(substr($firstline, 1, 1)) === 0xBB
and ord(substr($firstline, 2, 1)) === 0xBF;
}
function unsetbom(&$content) {
hasbom($content) and ($content[0] = substr($content[0], 3));
}
function write($filename, &$content) {
$file = fopen($filename, 'w');
fwrite($file, implode($content, ''));
fclose($file);
}
function filenames($path) {
$directory = opendir($path);
while (false != ($filename = readdir($directory))) strpos($filename, '.') !== 0 and $filenames[] = $filename;
closedir($directory);
return $filenames;
}
function process($path) {
$parent = opendir($path);
while (false != ($filename = readdir($parent))) {
echo $filename."\n";
if(strpos($filename, '.') === 0) continue;
if(is_dir($path.'/'.$filename)) {
process($path.'/'.$filename);
} else {
$content = file($path.'/'.$filename);
unsetbom($content);
write($path.'/'.$filename, $content);
}
}
closedir($parent);
}
process('/home/selfimpr/t');
解决方案 »
- 斐波那契数列代码错在哪里?
- php更新文章点击数
- smarty时间问题
- php 构造函数
- jpgraph安装问题求教,在线等
- SMARTY我只需要简单的模板功能,在发发表的时候要带哪几个文件??
- 启动apache时,为什么提示“通常每个套接字(协议/地址/端口)地址只能使用一次。make_sock could not bind to address0.0.0.0:80 no lis
- 哪里有支持PHP的免费空间???
- 页面提交出错,返回后如何保存原来填写的信息?
- php.ini配置session.gc_maxlifetime无效,session依旧能访问
- mysql 存储过程问题
- PHP怎么使用COOKIE的问题。。。。。。。
function process($path, $func='') {
$parent = opendir($path);
while (false != ($filename = readdir($parent))) {
echo $filename."\n";
if(strpos($filename, '.') === 0) continue;
$filename = $path.'/'.$filename;
if(is_dir($filename)) {
process($filename, $func);
} else {
if($func) $func($filename);
}
}
closedir($parent);
}/*** 删除 BOM 头的函数 ***/
function unsetbom($filename) {
$content = file_get_contents($filename);
$s = substr($content, 0, 3);
if(array_pop(unpack('H*',$s)) == 'efbbbf') {
file_put_contents($filename, substr($content, 3));
}
}/*** 调用示例 ***/
process('/home/selfimpr/t', 'unsetbom');