search
HomeBackend DevelopmentPHP Tutorial检查php文件中是否含有bom的函数_PHP

复制代码 代码如下:
/*检测并清除BOM*/
if(isset($_GET['dir'])){
$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);
}
}
}//end while
closedir($dh);
}//end if($dh
}//end function
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.");
}
} www.bitsCN.com
else return ("BOM Not Found.");
}//end function
function rewrite($filename, $data){
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}//end function
?>
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
dom和bom对象有哪些dom和bom对象有哪些Nov 13, 2023 am 10:52 AM

dom和bom对象有:1、“document”、“element”、“Node”、“Event”和“Window”等5种DOM对象;2、“window”、“navigator”、“location”、“history”和“screen”等5种BOM对象。

bom和dom有什么区别bom和dom有什么区别Nov 13, 2023 pm 03:23 PM

bom和dom在作用和功能、与JavaScript的关系、相互依赖性、不同浏览器的兼容性和安全性考虑等方面都有区别。详细介绍:1、作用和功能,BOM的主要作用是操作浏览器窗口,它提供了浏览器窗口的直接访问和控制,而DOM的主要作用则是将网页文档转换为一个对象树,允许开发者通过这个对象树来获取和修改网页的元素和内容;2、与JavaScript的关系等等。

dom和bom实现了什么dom和bom实现了什么Nov 20, 2023 pm 02:28 PM

DOM实现了对网页内容的动态访问和更新,BOM则提供了与浏览器窗口进行交互的API,包括控制浏览器的行为、获取浏览器和用户环境的信息,DOM主要用于操作网页内容,而BOM则主要用于操作浏览器窗口和与浏览器交互,两者共同构成了Web前端开发中重要的基础,为开发者提供了丰富的方法来控制和操作网页及浏览器,实现交互性强、用户体验良好的Web应用程序。

PHP bom的定义及其应用场景PHP bom的定义及其应用场景Mar 09, 2024 pm 09:36 PM

PHPBOM的定义及其应用场景BOM(ByteOrderMark),即字节顺序标记,是一种用来标示文本编码格式的特殊字符序列。在PHP开发中,BOM通常用来解决一些特定的编码问题,在一些情况下,如果不正确地处理BOM可能会导致页面显示乱码或其他问题的发生。本文将详细介绍PHPBOM的定义以及其应用场景,并附上具体的代码示例来让读者更好地理解。一、PH

php 代码怎么去掉bomphp 代码怎么去掉bomOct 20, 2022 am 09:29 AM

php代码掉bom的方法:1、使用“function clearbom($contents){...}”方式去掉文本中的bom头;2、通过“function checkBOM ($filename) {...}”方法检测并去掉bom头;3、通过“function SearchBOM($string) {...}”方法搜索当前文件是否有BOM并去除即可。

前端bom和dom什么区别前端bom和dom什么区别Nov 13, 2023 pm 02:36 PM

区别有:1、含义不同,bom是指浏览器对象模型,dom是指文档对象模型;2、结构不同,bom以浏览器窗口为中心,dom文档中的元素被表示为节点,并按照树状结构进行组织;3、交互方式不同,bom通过Window对象与JS进行交互,dom通过对象之间的嵌套和引用进行交互;4、应用范围不同,bom用于浏览器窗口和浏览器的交互,dom用于文档内容的操作和交互;5、发展趋势不同等等。

bom和dom的核心对象是什么bom和dom的核心对象是什么Nov 13, 2023 pm 02:49 PM

bom和dom的核心对象分别是window对象和document对象。window对象代表浏览器窗口,并提供了一系列方法和属性来操作浏览器窗口,窗口对象可以通过JavaScript代码来访问和控制,它提供了一些常用的方法。document对象代表了当前网页的文档,它提供了一系列方法和属性来操作网页的内容,通过document对象,可以访问和操作网页中的各个元素。

bom和dom是什么模型bom和dom是什么模型Nov 13, 2023 pm 05:08 PM

BOM是浏览器对象模型,而DOM是文档对象模型。BOM是一种用于描述浏览器窗口和浏览器提供的各种对象的模型,它是浏览器的核心组成部分,通过BOM可以访问和操作浏览器窗口、框架等对象。DOM提供了一组API,使开发人员能够通过脚本语言访问和操作文档中的元素和属性,其核心概念包括节点、元素、属性、文本等,DOM树的根节点是document对象,通过该对象可以访问整个文档的内容。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version