网站地图    收藏   

主页 > 后端 > dedecms >

解决织梦换服务器引起的页面不居中错位问题

来源:自学PHP网    时间:2014-11-30 17:03 作者: 阅读:次

[导读] 页面之所以错位是因为utf8格式的文件多了BOM头,只要把这些BOM头去掉就可以了,php代码如下,保存成php文件放在根目录中执行一次就行了,会自动去除文件头中的BOM.记住不要用记事本,用其他...

解决织梦换服务器引起的页面不居中错位问题

页面之所以错位是因为utf8格式的文件多了BOM头,只要把这些BOM头去掉就可以了,php代码如下,保存成php文件放在根目录中执行一次就行了,会自动去除文件头中的BOM.

记住不要用记事本,用其他的文本编辑器.

  1. //remove the utf-8 boms 
  2. //by magicbug at gmail dot com 
  3. if (isset($_GET['dir'])){ //要去除的文件目录,无参数则为文件当前目录。 
  4. $basedir=$_GET['dir']; 
  5. }else{ 
  6. $basedir = '.'; 
  7. } 
  8. $auto = 1; 
  9. checkdir($basedir); 
  10. function checkdir($basedir){ 
  11. if ($dh = opendir($basedir)) { 
  12.    while (($file = readdir($dh)) !== false) { 
  13.     if ($file != '.' && $file != '..'){ 
  14.      if (!is_dir($basedir."/".$file)) { 
  15.       echo "filename: $basedir/ 
  16. $file ".checkBOM("$basedir/$file")." 
  17. "; 
  18.      }else{ 
  19.       $dirname = $basedir."/". 
  20. $file; 
  21.       checkdir($dirname); 
  22.      } 
  23.     } 
  24.    } 
  25. closedir($dh); 
  26. } 
  27. } 
  28. function checkBOM ($filename) { 
  29. global $auto; 
  30. $contents = file_get_contents($filename); 
  31. $charset[1] = substr($contents, 0, 1); 
  32. $charset[2] = substr($contents, 1, 1); 
  33. $charset[3] = substr($contents, 2, 1); 
  34. if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && 
  35. ord($charset[3]) == 191) { 
  36.    if ($auto == 1) { 
  37.     $rest = substr($contents, 3); 
  38.     rewrite ($filename, $rest); 
  39.     return ("BOM found,automatically removed."); 
  40.    } else { 
  41.     return ("BOM found."); 
  42.    } //phpfensi.com 
  43. } 
  44. else return ("BOM Not Found."); 
  45. } 
  46. function rewrite ($filename, $data) { 
  47. $filenum = fopen($filename, "w"); 
  48. flock($filenum, LOCK_EX); 
  49. fwrite($filenum, $data); 
  50. fclose($filenum); 
  51. }

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论