<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • PHP網(wǎng)站建設(shè)之去除文件bom頭信息

            2023-03-06    分類: 網(wǎng)站建設(shè)

            BOM是用來判斷文本文件是哪一種Unicode編碼的標記,其本身是一個Unicode字符("\uFEFF"),位于文本文件頭部,BOM本來不影響代碼的解析,但是php除外,PHP會解析BOM,會輸出在頁面里,造成前端有占位發(fā)生布局位移,如果不了解的php BOM 就會對這個平白多出來的東西感到莫名其妙。
            我們?nèi)サ艟W(wǎng)站php文件里的BOM信息呢
            編輯器可以無保存bom文件,utf-8和utf-8 with bom ,要保存了bom文件 php會報錯namespace 必須是第一行的代碼,現(xiàn)在是bom信息是第一行,雖然你看不到但是他就是在第一行

            網(wǎng)站制作1

            我們怎么樣通過代碼的形式批量的去掉文件的bom信息
            在網(wǎng)站根目錄下新建一個nobomb.php的文件,文件的代碼為以下內(nèi)容。主要解決模板多出空的內(nèi)容、驗證碼不顯示等問題。然后在瀏覽器直接訪問運行nobom.php文件即可。
            <?php
            if(isset($_GET['dir'])){
            $basedir=$_GET['dir'];
            }else{
            $basedir='.';
            }
            $auto=1;
            checkdir($basedir);
            functioncheckdir($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);
            }
            }
            functioncheckBOM($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("<fontcolor=red>BOMfound,automaticallyremoved.</font>");
            }else{
            return("<fontcolor=red>BOMfound.</font>");
            }
            }elsereturn("BOMNotFound.");
            }
            functionrewrite($filename,$data){
            $filenum=fopen($filename,"w");
            flock($filenum,LOCK_EX);
            fwrite($filenum,$data);
            fclose($filenum);
            }

            網(wǎng)站制作2

            運行上面的代碼就可以清除文件的bom信息

            網(wǎng)站制作3

            上面的截圖看是沒有發(fā)現(xiàn)帶有bom的文件的,有bom的文件 會出現(xiàn)字體加紅色。
            去掉后訪問網(wǎng)站訪問正常

            網(wǎng)站制作4

            網(wǎng)頁題目:PHP網(wǎng)站建設(shè)之去除文件bom頭信息
            文章鏈接:http://www.jbt999.com/news37/241887.html

            網(wǎng)站建設(shè)、網(wǎng)絡推廣公司-創(chuàng)新互聯(lián),是專注品牌與效果的網(wǎng)站制作,網(wǎng)絡營銷seo公司;服務項目有網(wǎng)站建設(shè)

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

            營銷型網(wǎng)站建設(shè)

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 久久性视频| 精品免费一区二区三区四区 | 美女操逼AV | 小黄网站在线观看 | 你操我操综合 |