- 因为本人才疏学浅,对问题认知不免有误差,本着学习与共享的精神和你们一块儿探讨,如有不对之处,望你们多多批评指正。
-
- <?php
-
-
- function hasbom(&$content) {
- $firstline = $content[0];
- return ord(substr($firstline, 0, 1)) === 0xEF
- and ord(substr($firstline, 1, 1)) === 0xBB
- and ord(substr($firstline, 2, 1)) === 0xBF;
- }
- function unsetbom(&$content) {
- hasbom($content) and ($content[0] = substr($content[0], 3));
- echo '该文件有bom头标';
- }
- function write($filename, &$content) {
- $file = fopen($filename, 'w');
- fwrite($file, implode($content, ''));
- fclose($file);
- }
- function filenames($path) {
- $directory = opendir($path);
- while (false != ($filename = readdir($directory))) strpos($filename, '.') !== 0 and $filenames[] = $filename;
- closedir($directory);
- return $filenames;
- }
- function process($path) {
- $parent = opendir($path);
- while (false != ($filename = readdir($parent))) {
- echo $filename."/n";
- if(strpos($filename, '.') === 0) continue;
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename)) {
- process($path.DIRECTORY_SEPARATOR.$filename);
- } else {
- $content = file($path.DIRECTORY_SEPARATOR.$filename);
- unsetbom($content);
- write($path.DIRECTORY_SEPARATOR .$filename, $content);
- }
- }
- closedir($parent);
- }
- process('/tmp/mrc');
- ?>