一鍵去除網(wǎng)頁BOM屬性【解決亂碼,頭部空白,驗證碼不顯示問題】幾個常出現(xiàn)的問題: 1.網(wǎng)站打開空白 2.頁面頭部出現(xiàn)多余的空白 3.網(wǎng)站出現(xiàn)亂碼,如“锘�” 4.后臺登錄驗證碼不顯示 解決方案: 1.選用專業(yè)的編輯器,例如notepad++,sublime,editplus這樣不會自動簽名。 2.sublime通過如下操作File -> Save with Encoding -> UTF-8保存后即可去除bom 3.notepad++選中格式 -> 以UTF-8格式編碼 選項即可去除 4.用如下方法可一次性清理網(wǎng)頁所有文本文件的bom 復(fù)制下面代碼 <?php
$dir=dirname(__FILE__);
if(isset($_GET["act"]) && $_GET["act"] == "del" ){ //Del the file!!
$filename=basename($_SERVER['PHP_SELF']);
@unlink($filename);
exit('Error:File Not Found!');
}
echo "The document:".$dir." <a href=\"?act=del\" >[Del the delbom.php file]</a><BR/>";
if (!is_dir($dir))
die("$dir not exists");
$auto = 1;
checkdir($dir);
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/>\n";
}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>\n");
} else {
return ("<font color=red>BOM found.</font>\n");
}
}
else return ("BOM Not Found.\n");
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>復(fù)制上面的代碼 使用方法:復(fù)制上面代碼到一個新建的delbom.php(用記事本或者是文本編輯器打開此文件)的文件中,上傳到網(wǎng)站根目錄,然后訪問您的站點(diǎn),比如http://www.**.com/delbom.php 即可清理所有網(wǎng)頁中存在的bom便簽。
|
|||||
| >> 相關(guān)文章 | |||||
|
|
|||||
400-028-5800
028-62778877
您好,非正常上班時間若有緊急技術(shù)問題,請撥總機(jī)后按7號鍵, 其他問題請?zhí)峤还位蛟谏习鄷r間聯(lián)系,謝謝支持!