百度了以后,发现好多的解决方法都是说的把文件存储为utf-8无bom模式,可是发现我用了这个方法以后,这字符串仍是在~php
后面经人提点说有php方法能够去除~而后找到如下代码:html
1 <?php 2 if (isset($_GET['dir'])) { //设置文件目录 3 $basedir = $_GET['dir']; 4 } else { 5 $basedir = '.'; 6 } 7 8 $auto = 1; 9 checkdir($basedir); 10 11 function checkdir($basedir) 12 { 13 if ($dh = opendir($basedir)) { 14 while (($file = readdir($dh)) !== false) { 15 if ($file != '.' && $file != '..') { 16 if (!is_dir($basedir . "/" . $file)) { 17 echo "filename: $basedir/$file " . checkBOM("$basedir/$file") . " <br>"; 18 } else { 19 $dirname = $basedir . "/" . $file; 20 checkdir($dirname); 21 } 22 } 23 } 24 closedir($dh); 25 } 26 } 27 function checkBOM($filename) 28 { 29 global $auto; 30 $contents = file_get_contents($filename); 31 $charset[1] = substr($contents, 0, 1); 32 $charset[2] = substr($contents, 1, 1); 33 $charset[3] = substr($contents, 2, 1); 34 if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) { 35 if ($auto == 1) { 36 $rest = substr($contents, 3); 37 rewrite($filename, $rest); 38 return ('<font color="red">BOM found, automatically removed.</font>'); 39 } else { 40 return ('<font color="red">BOM found.</font>'); 41 } 42 } else 43 return ("BOM Not Found."); 44 } 45 46 function rewrite($filename, $data) 47 { 48 $filenum = fopen($filename, "w"); 49 flock($filenum, LOCK_EX); 50 fwrite($filenum, $data); 51 fclose($filenum); 52 } 53 ?>
具体使用方法以下(此流程只针对于php小白~):服务器
1.新建一个php文件,命名你本身随便取,我这里就取名为:withoutBoml.php;网站
2.将文件上传到根目录下面(所谓的根目录就是wwwroot或者htdocs);spa
3.而后运行此段php代码:http://你的网站域名/withoutBoml.php(好比说你的网站是www.haha.com,那么就运行http://www.haha.com/withoutBoml.php).rest
运行完以后再看你的网站,发现真的没有了哦~~ code
10月24日更新htm
感谢@ 都瓦克因 ,告诉了我报错缘由是return里面输出的html语句双引号冲突了,把最外层的双引号修改成单引号就能够了;blog