一键去除网页BOM属性【解决乱码,头部空白,#65279问题】
生活随笔
收集整理的這篇文章主要介紹了
一键去除网页BOM属性【解决乱码,头部空白,#65279问题】
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
幾個(gè)常出現(xiàn)的問(wèn)題:
?
1.網(wǎng)站打開(kāi)空白
?
2.頁(yè)面頭部出現(xiàn)多余的空白
?
3.網(wǎng)站出現(xiàn)亂碼,如“锘�”
?
解決方法可以是:
?
1.選用專業(yè)的編輯器,例如notepad++,sublime,editplus這樣不會(huì)自動(dòng)簽名。
?
2.sublime通過(guò)如下操作File -> Save with Encoding -> UTF-8保存后即可去除bom
?
3.notepad++選中格式 -> 以UTF-8格式編碼 選項(xiàng)即可去除
?
<?php if (isset($_GET['dir'])){ //設(shè)置文件目錄 $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); } ?>?
使用方法:復(fù)制上面代碼到一個(gè)新建的delbom.txt的文件中,上傳到網(wǎng)站根目錄,然后將delbom.txt改為delbom.php,最后直接前臺(tái)訪問(wèn)該文件即可。
?
原文鏈接https://zhangzifan.com/delbom-php.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/supe/p/6687839.html
總結(jié)
以上是生活随笔為你收集整理的一键去除网页BOM属性【解决乱码,头部空白,#65279问题】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Manjaro安装scrt8.3 20
- 下一篇: HttpServletResponse.