This article introduces, in PHP to remove the BOM header instance code, BOM in the file head, occupy three bytes, sometimes need to remove this information. In this paper, we can make a reference for the example. Remove the BOM header PHP code, as follows:
";} 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._csdn.net");} 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);}? > Attached, BOM header information description. In the Utf-8 encoded file, the BOM is in the file header, occupies three bytes, which is used to indicate that the file belongs to Utf-8 encoding. PHP does not recognize the BOM header, and editing Utf-8 encoding with Notepad will cause an error. Remove the BOM header, you can: 1, editplus to the BOM Header method Editor adjusted to UTF8 encoding format, the saved file will be preceded by a string of hidden characters (also known as the BOM), for the editor to identify whether the file is UTF8 encoded. Run EditPlus, click Tools, select Preferences, select files, UTF-8 identity Select always delete signatures, and then edit and save php files without BOM. 2, UltraEdit removal of the BOM head method open the file, save as the option to choose the encoding format (utf-8 no BOM head), you can. 3, specifically write the removal of the document BOM header program, now published, you can put in the project root directory, and then run. |