Created
May 27, 2016 02:33
-
-
Save huynhducduy/14d481c2df212adbe93413740b9d7c4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function checkBOM($filePath) { | |
$isBOM = false; | |
if (is_file($filePath)) { | |
$str = file_get_contents($filePath); | |
$bom = pack("CCC", 0xef, 0xbb, 0xbf); | |
if (0 == strncmp($str, $bom, 3)) { | |
$isBOM = true; | |
$str = substr($str, 3); | |
file_put_contents($filePath, $str); | |
} | |
} | |
return $isBOM; | |
} | |
function read_dir($dir_path) { | |
if ($handle = opendir($dir_path)) { | |
while (false !== ($entry = readdir($handle))) { | |
if ($entry != "." && $entry != "..") { | |
$path_file = $dir_path . '/' . $entry; | |
if (is_file($path_file)) { | |
if (checkBOM($path_file)) { | |
echo $path_file . "\n"; | |
} | |
} else { | |
read_dir($path_file); | |
} | |
} | |
} | |
closedir($handle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment