- 因爲本人才疏學淺,對問題認知不免有誤差,本着學習與共享的精神和你們一塊兒探討,如有不對之處,望你們多多批評指正。
-
- <?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');
- ?>