Need to remove the BOM, put the tool.php file in the attachment to the target directory, and then access tool.php in the browser!
Copy Code code as follows:
<?php
This file is used to quickly test UTF8 encoded files that are not BOM-added and can be removed automatically
$basedir = "."; Modifies the directory to be detected for this behavior, and the point represents the current directory
$auto = 1; Whether the found BOM information is automatically removed. 1 for Yes, 0 for No.
Don't 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"). "<br>";
}
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 ("<font Color=red>bom found, automatically removed.</font>");
} else {
Return ("<font Color=red>bom found.</font>");
}
}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 Code code as follows:
<?php
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"). "<br>";
}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 ("<font Color=red>bom found, automatically removed._<a href=http://www.joyphper.net>http:// Www.joyphper.net</a></font> ");
} else {
Return ("<font Color=red>bom found.</font>");
}
}
else return ("BOM not Found.");
}
function rewrite ($filename, $data) {
$filenum = fopen ($filename, "w");
Flock ($filenum, LOCK_EX);
Fwrite ($filenum, $data);
Fclose ($filenum);
}
?>