찾다
php教程php手册检查php文件中是否含有bom的php文件

检查php文件中是否含有bom的php文件

Jun 13, 2016 am 10:49 AM
bomdirgetissetphp문서조사하다발각분명한~의

/*检测并清除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.2cto.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 
?>
 
 

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

VSCode Windows 64비트 다운로드

VSCode Windows 64비트 다운로드

Microsoft에서 출시한 강력한 무료 IDE 편집기

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전