PHP Remove the BOM header code sharing

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.