php怎样输出多个空格,【整理】解决php输出时出现多余的空格或者换行
由于某度眾所周知的舉動,讓我搬離寫了5年的渣度空間,準備把技術性的文章定在CSDN了。這些都是文章備份。勿怪。。
1.要查清自己本身有沒有echo 或者exit空格或者換行, 2.一定要保證php文件里<?php ?>標簽外沒有多余的回車,換行。 3.這些都排查了之后,如果是utf8編碼的文件,還會輸出一個多余的空格回車。做xml傳輸時經常死在這多余的空白上面。這是由于BOM文件頭造成的。可以使用ultraedit打開文件,另存為無BOM的文件即可。如果文件太多,可以使用以下文件保存到根目錄執行一次: <?php //remove the utf-8 boms //by magicbug at gmail dot com 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")."
"; }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 ("BOM found, automatically removed."); } else { return ("BOM found."); } } else return ("BOM Not Found."); } function rewrite ($filename, $data) { $filenum = fopen($filename, "w"); flock($filenum, LOCK_EX); fwrite($filenum, $data); fclose($filenum); } ?>
總結
以上是生活随笔為你收集整理的php怎样输出多个空格,【整理】解决php输出时出现多余的空格或者换行的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: webpack 入口文件 php,web
- 下一篇: 开启php的ssl,php怎么开启ssl