Home  >  Article  >  Backend Development  >  PHP batch detection and removal of file BOM header code examples_PHP tutorial

PHP batch detection and removal of file BOM header code examples_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:30:12804browse

The following code is PHP code to remove the BOM information of all files in the current directory and subdirectories, create a new file, place it in the root directory, and then access it with a browser.

Copy code The code is as follows:

if (isset($_GET['dir'] )) { //Set the file directory
$basedir = $_GET['dir'];
} else {
$basedir = '.';
}

$auto = 1;
checkdir($basedir);

function checkdir($basedir)
{
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {< | basedir/$file " . checkBOM("$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]) == " rest);
          return ("BOM found, automatically removed."); "red">BOM found.
function rewrite($filename, $data)
{
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum , $data);
fclose($filenum);
}
?>





http://www.bkjia.com/PHPjc/767089.html


www.bkjia.com

true

http: //www.bkjia.com/PHPjc/767089.html

TechArticle

The following code is the PHP code to remove the BOM information of all files in the current directory and subdirectories, create a new file, and put it Go to the root directory and access it with a browser. Copy the code The code is like...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn