This article mainly introduces the solution to the problem of invisible character 65279 in php, which is actually the BOM header of the UTF-8 file. This article provides a small program to delete the BOM header of the php file, for more information, see CSDN. I found a problem with php output blank and invisible character 65279 on the internet. I sent this 65279 character to php to mark the file as UTF-8 encoded, the output will be output to the client together, causing the client to fail to match the string if ajax is used to obtain the return value.
Php stealth character 65279 is explained as follows:
UTF-8 files can be divided into two formats: BOM and BOM.
What is BOM?
"Ef bb bf" these three bytes are called BOM, full name is "Byte Order Mard ". In utf8 files, BOM is often used to indicate that this file is a UTF-8 file, and BOM is intended to be used in utf16.
The bom is output when the UTF-8 file is output in php. therefore, to use UTF-8 in php, you must use a UTF-8 file without the bom header.
The commonly used text editing software supports UTF-8 file storage in different ways. pay special attention when using it.
For example:
1. when you use ultraedit, there are two options for "UTF-8" and "UTF-8-no BOM" when you save it.
2. Windows Notepad stores bom.
3. different versions of the EditPlus software support different UTF-8 storage features. for example, Version 2.31 saves data without bom and version 2.11 saves data with bom.
Remove the UTF-8 file header:
1. use ultraedit to save, select "UTF-8-no BOM"
2. a very useful php program running in the root directory of the site will remove the bom headers of all UTF-8 files in the directory. the code is as follows:
//remove the utf-8 boms //by magicbug at gmail dot com if (isset($_GET['dir'])){ //config the basedir $basedir=$_GET['dir']; }else{ $basedir = '.'; } $auto = 1; checkdir($basedir); function checkdir($basedir){ if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..'){ if (!is_dir($basedir."/".$file)) { echo "filename $basedir/$file ".checkBOM("$basedir/$file")."
"; }else{ $dirname = $basedir."/".$file; checkdir($dirname); } } } closedir($dh); } } function checkBOM ($filename) { global $auto; $contents = file_get_contents($filename); $charset[1] = substr($contents, 0, 1); $charset[2] = substr($contents, 1, 1); $charset[3] = substr($contents, 2, 1); if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) { if ($auto == 1) { $rest = substr($contents, 3); rewrite ($filename, $rest); return ("BOM found, automatically removed."); } else { return ("BOM found."); } } else return ("BOM Not Found."); } function rewrite ($filename, $data) { $filenum = fopen($filename, "w"); flock($filenum, LOCK_EX); fwrite($filenum, $data); fclose($filenum); }