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
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'