喵宅苑 MewoGarden × 技术宅社区II | Z站 Z Station 棒棒哒纯文字二次元技术社区

正文

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

作者:mayan
问题: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] 然后浏览器执行; 最后删除代码; 相关地址

回复

不错的东西

作者:sniu
不错的东西,但是似乎没什么人回复,原因可能在于楼主在标题里特别提出了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嵌套超过三层的时候你就需要考虑逻辑结构是不是需要优化了
查看回复
上一页
下一页
0%
闽ICP备2022013136号闽公网安备35092202000188号
站点地图友情链接:
喵宅苑
喵空间社区程序
喵宅苑 静态版
络合兔
Lanzainc
技术宅
小五四博客
莉可POI
Mithril.js
枫の主题社
Project1
午后少年
机智库
七濑胡桃
xiuno
幻想の日常
魂研社
Nothentai
0xffff
欲望之花
泽泽社长