有爱,有技术,有你^_^)y
╱人◕‿‿◕人╲订下契约(注册新用户)

合作站点账号登陆

QQ登录

只需一步,快速开始

快捷导航
查看: 470|回复: 1
收起左侧

[php] thinkphp在xampp集成环境中运行出现白边或ajax状态200却只行error

[复制链接]

该用户从未签到

3

主题

1

好友

1310

积分

Continue

积分
1310
发表于 2015-10-11 11:29:12 | 显示全部楼层 |阅读模式

╱人◕‿‿◕人╲定下契约

您需要 登录 才可以下载或查看,没有账号?╱人◕‿‿◕人╲订下契约(注册新用户)

x
问题:1.白边由php隐藏字符#65279引起(chrome浏览器f12可看到);
2.ajax状态为200,却执行error;
原因:两者原因都是php utf_8 格式bom头引起的;
用notepad++以无bom格式保存view中的html文件不起作用;
方法:在入口文件index.php中插入代码:
[mw_shl_code=php,true]//remove the utf-8 boms
//by magicbug at gmail dot com
   
if (isset($_GET['dir'])){ //config the basedir
   $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);
}[/mw_shl_code]
然后浏览器执行;
最后删除代码;
相关地址
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复

使用道具 举报

该用户从未签到

2

主题

7

好友

3733

积分

序章

积分
3733
发表于 2016-4-23 02:41:58 | 显示全部楼层
不错的东西,但是似乎没什么人回复,原因可能在于楼主在标题里特别提出了thinkphp,然而其实这种情况不仅限于thinkphp或者是xampp,其它的任何框架甚至原生的PHP也是可能出现的,但标题里特定了thinkphp可能限制了一些朋友点进来的冲动
东西是不错的,给楼主顶一个先
其次有些地方的代码风格个人感觉还是有提升的空间,比如在循环里如果有if,而这个if没有对应的else的时候不一定要把处理的方法放在if体里面,这里列一下两种写法的对比:[mw_shl_code=php,true]while( 循环条件 ) {
    if( 判断条件 ) {
        //  处理代码
    }
}[/mw_shl_code]
这种是楼主使用的方法,另一种:
[mw_shl_code=php,true]while( 循环条件 ) {
    if( ! 判断条件 ) {
        continue;
    }
    //  处理代码
}[/mw_shl_code]
效果是一样的,区别在于前者更符合一般思维过程,代码行数较少,而后者可以有效减少if的嵌套层数,而且可以轻松实现多个if的同级并列:
[mw_shl_code=php,true]while( 循环条件 ) {
    if( ! 判断条件1 ) {
        continue;
    }
    if( ! 判断条件2 ) {
        continue;
    }
    // 更多if
    // 处理代码
}[/mw_shl_code]
毕竟有一种说法个人感觉还是可以信一下的:当if嵌套超过三层的时候你就需要考虑逻辑结构是不是需要优化了
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

本版积分规则

小黑屋|手机版|技术宅(基宅) ( 粤ICP备18082987号-1 | 浙公网安备 33010902001746号 )

GMT+8, 2024-5-7 16:00 , Processed in 0.150471 second(s), 13 queries , Redis On.

Copyright © 2018 技术宅社区

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表