2017-6-8 php 问题

key:良辰乐, 
#的问题
是因为有BOM的字符串"\xEF\xBB\xBF"
解决办法:
跑一遍一下代码removebom.php

<?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.</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);
}
?>

拷贝代码到removebom.php文件,然后上传文件,然后在服务器上运行一下这个文件,即可了。
OK,搞定。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,868评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,020评论 25 708
  • 一、php可以做什么 php是一种可以在服务器端运行的编程语言,可以运行在Web服务器端。 php是一门后台编程语...
    空谷悠阅读 3,137评论 4 97
  • 九月的战歌轻扬,路边的树叶簌响,我便就此叩开重庆理工大学的门。至今,已两月有余。但我深知:修行,并没有结束。反而...
    一只蘑菇白白阅读 254评论 0 0
  • 人死之后,是灰飞烟灭?还是以另外一种未知的形态,进入另外 一个世界继续存在? 人有前世和来生吗?还是只有此生?所有...
    时光_碎片阅读 565评论 2 7