PHP finds files with BOM labels and removes BOM labels

Source: Internet
Author: User
Tags ord
In a very large project, it is difficult to find out which file is the document containing the BOM label, if we manually open each file to check, it will consume our large amount of time, and very troublesome, we can directly through the PHP program can easily find out the current project or directory of all the files , whether this BOM label is included.

The code is as follows:

 ";}  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);}

In fact, these code is also I find share on the Internet, because this period of time is busy, so there is no time to optimize the code, currently only check the current directory with the BOM label files, you can also add their own functions, such as

Automatically detects all files for subdirectories under the current project.

You can also select a file in a directory instead

  • 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.