zoukankan      html  css  js  c++  java
  • 一键去除网页BOM属性【解决乱码,头部空白,&#65279问题】

     

    几个常出现的问题:

     

    1.网站打开空白

     

    2.页面头部出现多余的空白

     

    3.网站出现乱码,如“锘�”

     

    解决方法可以是:

     

    1.选用专业的编辑器,例如notepad++,sublime,editplus这样不会自动签名。

     

    2.sublime通过如下操作File -> Save with Encoding -> UTF-8保存后即可去除bom

     

    3.notepad++选中格式 -> 以UTF-8格式编码 选项即可去除

     

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

     

    使用方法:复制上面代码到一个新建的delbom.txt的文件中,上传到网站根目录,然后将delbom.txt改为delbom.php,最后直接前台访问该文件即可。

    原文链接https://zhangzifan.com/delbom-php.html

     

  • 相关阅读:
    vs.net2003里添加邮件发件人身份验证
    Linux下用PYTHON查找同名进程
    修改机器名后要修改IIS匿名访问用户
    [C#]使用MYSQL数据库
    JIRA OutOfMemoryErrors
    获取linux下当机堆栈
    python调用pipe
    [探讨]一次性工具软件
    GGSN
    三层交换机的作用
  • 原文地址:https://www.cnblogs.com/supe/p/6687839.html
Copyright © 2011-2022 走看看