批量除去php页面的bom,页面meta跑到body中就是这个问题
2013-12-13 14:28
627 查看
<?php
if (isset($_GET['dir'])){ //设置文件目录
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}
$auto = 1;
checkdir($basedir);
function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..'){
if (!is_dir($basedir."/".$file)) {
echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}
function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return ("<font color=red>BOM found, automatically removed.</a></font>");
} else {
return ("<font color=red>BOM found.</font>");
}
}
else return ("BOM Not Found.");
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>
if (isset($_GET['dir'])){ //设置文件目录
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}
$auto = 1;
checkdir($basedir);
function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..'){
if (!is_dir($basedir."/".$file)) {
echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}
function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return ("<font color=red>BOM found, automatically removed.</a></font>");
} else {
return ("<font color=red>BOM found.</font>");
}
}
else return ("BOM Not Found.");
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>
相关文章推荐
- PHP 页面编码声明方法详解(header或meta,解决中文乱码问题)
- PHP批量去除Unicode 签名 BOM(smarty IE6不居中问题)
- ecmobile-页面空白,也没异常提示,一般就是这个问题
- php读取csv文件后,uft8 bom导致在页面上显示出现问题的解决方法
- php读取csv文件后,uft8 bom导致在页面上显示出现问题
- link标签和script标签跑到body下面,网页顶部有空白,UTF-8 BOM问题
- PHP 页面编码声明方法详解(header或meta,解决中文乱码问题)
- php读取csv文件后,uft8 bom导致在页面上显示出现问题的解决方法
- PHP中遇到BOM、<feff>编码导致json_decode函数无法解析问题
- php中文乱码问题以及页面显示部分后台代码问题
- PHP Header用于页面跳转要注意的几个问题总结
- 一上传带图片的新闻.提交后就是个白屏 php 168 白屏问题?
- php页面,mysql数据库转utf-8乱码,utf-8编码问题总结
- 关于webpack打包vue项目后的页面body为空的问题
- 关于php 接口问题(php接口主要也就是运用curl,curl函数)
- 来谈一下我在使用fo-dicom开源库时遇到的一些问题,这篇主要就是针对从RIS那获取worklist的,希望能帮助那些刚接触这个开源库的。
- 使用PHP header进行页面跳转出现的问题解疑
- phpexcel导出的问题,在本地没有问题,但是在服务器上就会报这个访问不到的错误
- 关于首页能打开,而其他页面404错误,但使用index.php后就能打开的问题
- PHP批量删除、清除UTF-8文件BOM头的代码实例