当前位置:首页 > CMS教程 > DeDecms > 列表

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

发布:smiling 来源: PHP粉丝网  添加日期:2014-11-07 09:02:32 浏览: 评论:0 

页面之所以错位是因为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. }

Tags: 页面不居中 dede页面错位

分享到: