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都不会导致问题。
去掉bom头的办法,简单的是下面两种:
1、editplus去bom头的方法
编辑器调整为utf8编码格式后,保存的文件前面会多出一串隐藏的字符(也即是bom),用于编辑器识别这个文件是否是以utf8编码。运行editplus,点击工具,选择首选项,选中文件,utf-8标识选择 总是删除签名,然后对php文件编辑和保存后的php文件就是不带bom的了。
2、ultraedit去除bom头办法
打开文件后,另存为选项的编码格式里选择(utf-8 无bom头),确定就ok了。
对于php程序需要去除bom头的也可以使用目录下的92wcms.php程序去除。
请用一下代码运行一次
<?phpif(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 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);}?>
推荐学习:《thinkphp视频教程》
以上就是thinkphp怎么去除 bom的详细内容。