How to Remove Byte Order Marks (BOMs) from the Beginning of a File
Problem:
You encounter an issue with a CSS file containing invisible characters, denoted by , that disrupt its proper functioning when read by PHP. The file is saved in UTF-8 encoding, but removing the characters manually is challenging.
Answer:
The characters you are observing are known as Byte Order Marks (BOMs). A BOM is a Unicode character that indicates the byte order (endianness) of a file. In this case, the UTF-8 BOM signifies that the file uses UTF-8 encoding.
Solutions:
awk 'sub(/^\xEF\xBB\xBF/, "")' input.css > output.css
<?php mb_internal_encoding('UTF-8'); // Read and process CSS files mb_internal_encoding('previous encoding'); // Restore previous encoding ?>
Note:
The above is the detailed content of How to Remove Byte Order Marks (BOMs) from a UTF-8 File?. For more information, please follow other related articles on the PHP Chinese website!