Delphi Unit file PHP code for batch removal of BOM in PHP file

Source: Internet
Author: User
Tags flock ord
Need to remove BOM, put the tool.php file in the attachment to the target directory, and then access the tool.php in the browser!

Copy the Code code as follows:


This file is used to quickly test whether UTF8 encoded files are added to the BOM and can be automatically removed
$basedir = "."; Modify this behavior to detect the directory where the point represents the current directory
$auto = 1; Whether the discovered BOM information is automatically removed. 1 for Yes, 0 for No.
Do not change the following
if ($dh = Opendir ($basedir)) {
while (($file = Readdir ($DH))!== false) {
if ($file! = '. ' && $file! = ': ' &&!is_dir ($basedir. " /". $file))
echo "FileName: $file". Checkbom ("$basedir/$file"). "
";
}
Closedir ($DH);
}
function Checkbom ($filename) {
Global $auto;
$c
$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);
}
?>


PHP bulk removal of BOM code in PHP files

Copy the Code code as follows:


if (Isset ($_get[' dir ')) {//Set file directory
$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._http://www.joyphper.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);
}
?>

The above describes the Delphi unit files in bulk to remove the PHP file BOM php code, including the Delphi unit file content, I hope the PHP tutorial interested in a friend helpful.

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