Home > Backend Development > PHP Tutorial > How to use PHP to batch remove UTF8 BOM information from files_PHP Tutorial

How to use PHP to batch remove UTF8 BOM information from files_PHP Tutorial

WBOY
Release: 2016-07-21 15:00:29
Original
831 people have browsed it

Principle:
UTF8 file, in order to add identification information, Microsoft has BOM: BOM - Byte Order Mark, which is defaulted on Windows and other platforms The edited UTF8 file will add 3 bytes of tag information to the header. Our PHP engine will completely read the entire PHP code document during processing. If the PHP file header contains BOM information, a blank will be output. In many cases, Sometimes it will cause problems, such as our session cannot work, cookies cannot be set, etc.

Solution:
Recognize the 3-byte information of the header BOM and then eliminate it. However, generally we don’t know which file has a BOM, or there are many files. At this time, batch processing is needed. The following code mainly shows the batch processing situation, which should be helpful to everyone in their work.

Execution method:
Set a path and execute it directly.

Copy the code The code is as follows:

// Set the root directory where you want to clear the BOM (All subdirectories and files will be scanned automatically)
$HOME = dirname(__FILE__);
// If it is a Windows system, change to: $WIN = 1;
$WIN = 0;
?>




UTF8 BOM Cleaner