Home  >  Article  >  Backend Development  >  php BOM problem

php BOM problem

巴扎黑
巴扎黑Original
2016-11-10 09:44:111269browse

In recent collaborative development projects, I always found that the output of PHP was wrong. The code was exactly the same and it didn't work. Later, I thought there was a problem with the encoding and found out that they were all utf-8. Finally, after deleting the file contents, I found that there were still 3 characters in size. Use the vim -b command. After opening it, I found and I feel like the problem lies here.

Later I found out that this is the BOM in utf-8. What's disgusting is that the BOM will be output along with the echo, causing errors.

Attached are a few commands to find and remove BOM

In vim:

Java code

#Set UTF-8 encoding

:set fileencoding=utf-8

#Add BOM

:set bomb

#Delete BOM

:set nobomb

#Query BOM

:set bomb?

grep:

Java code

//Find

grep -I -r -l $'xEFxBBxBF' / path

//Replacement

grep -I -r -l $'xEFxBBxBF' /path | xargs sed -i 's/^xEFxBBxBF//g'

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn