thinkphp去除bom的方法:1、運行editplus,點擊“工具”,選擇“首選項”,然后設置“UTF-8標識”;2、通過ultraedit打開文件,在另存為選項的編碼格式里選擇“utf-8無bom頭”;3、使用目錄下的“92wcms.php”程序去除bom即可。
本教程操作環境:windows7系統、thinkphp5版、Dell G3電腦。
thinkphp怎么去除 bom?
thinkphp清除BOM方法??
在utf-8編碼文件中BOM在文件頭部,占用三個字節,用來標示該文件屬于utf-8編碼,現在已經有很多軟件識別bom頭,但是還有些不能識別bom頭,比如PHP就不能識別bom頭,這也是用記事本編輯utf-8編碼后執行就會出錯的原因了。BOM只有在WINDOWS下采用“記事本”存儲為UTF-8時才會有,這個可以用WINHEX把開始的2個字節刪掉。在dreamweaver里面編碼設置里面可以設置是否帶BOM,一般只要php輸出的不是圖片(GDI Stream),BOM都不會導致問題。
立即學習“PHP免費學習筆記(深入)”;
去掉bom頭的辦法,簡單的是下面兩種:
1、editplus去BOM頭的方法
編輯器調整為UTF8編碼格式后,保存的文件前面會多出一串隱藏的字符(也即是BOM),用于編輯器識別這個文件是否是以UTF8編碼。運行Editplus,點擊工具,選擇首選項,選中文件,UTF-8標識選擇 總是刪除簽名,然后對PHP文件編輯和保存后的PHP文件就是不帶BOM的了。
2、ultraedit去除bom頭辦法
打開文件后,另存為選項的編碼格式里選擇(utf-8 無bom頭),確定就ok了。
對于PHP程序需要去除Bom頭的也可以使用目錄下的92wcms.php程序去除。
請用一下代碼運行一次
<?php if(isset($_GET['dir'])){ //config the basedir $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>BOM?found,automatically?removed.</font>"); }?else{ return("<font>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); } ?>
推薦學習:《thinkPHP視頻教程》