utf-8 bom 제거 코드. php 파일 첨부

utf-8 bom 제거 코드. php 파일 첨부

호스트에서 모든 화일을 검사한 다음에

utf-8 bom인 화일이 있다면 출력시켜주는 코드

첨부

 

$file = 'utf8file.ext';
if ( file_get_contents($file,NULL,NULL,0,3)=="\xEF\xBB\xBF" ) file_put_contents($file,file_get_contents($file,NULL,NULL,3));

 

function remove_utf8_bom($text)
{
    $bom = pack('H*','EFBBBF');
    $text = preg_replace("/^$bom/", '', $text);
    return $text;
}

 

폴더검사

function getDirContents($dir, &$results = array()) {
    $files = scandir($dir);

    foreach ($files as $key => $value) {
        $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
        if (!is_dir($path)) {
            $results[] = $path;
        } else if ($value != "." && $value != "..") {
            getDirContents($path, $results);
            $results[] = $path;
        }
    }

    return $results;
}


var_dump(getDirContents('./'));

Comments

Category
Facebook Twitter GooglePlus KakaoStory KakaoTalk NaverBand