最近在开发过程中,发现页面 响应在首行都会输出一行空白,这个问题初步搜索说是 UTF-8 BOM
问题。人工一个一个文件排查是很耗时的,一“翻”谷歌之后,发现了一款检测神奇 phptags tag tidier 。
解决办法如下(似乎直接下载 phptags-1.2.phar
使用不行):
# 直接下载 phptags 源码
wget http://include-once.org/p/phptags/phptags
# 追加可写权限
chmod +x phptags
# /php/project/folder 项目文件夹目录
php phptags --whitespace /php/project/folder
官网提供了更多的使用示例:
usage examples
phptags --whitespace *.php cleans up spaces or UTF-8 BOM issues before opening and after close tags
phptags --warn directory/ searches through a directory and just warns about whitespace issues
phptags --close --long --tokenizer *.php adds close tags, converts open tags into long form <?php and uses the more reliable --tokenizer mode (instead of --regex)
phptags --unclosed --shortall dir/ ../*.tpl includes/ converts all tags into short forms, and strips close tags of a document (it's advised to rather have whitespace issues fixed than keep using the newcomer workaround)