php howto ignore file with bom

Solutions on MaxInterview for php howto ignore file with bom by the best coders in the world

showing results for - "php howto ignore file with bom"
Gabriele
16 Feb 2018
1<?php 
2function fopen_utf8 ($filename) { 
3    $file = @fopen($filename, "r"); 
4    $bom = fread($file, 3); 
5    if ($bom != b"\xEF\xBB\xBF") 
6    { 
7        return false; 
8    } 
9    else 
10    { 
11        return true; 
12    } 
13} 
14
15function file_array($path, $exclude = ".|..|design", $recursive = true) { 
16    $path = rtrim($path, "/") . "/"; 
17    $folder_handle = opendir($path); 
18    $exclude_array = explode("|", $exclude); 
19    $result = array(); 
20    while(false !== ($filename = readdir($folder_handle))) { 
21        if(!in_array(strtolower($filename), $exclude_array)) { 
22            if(is_dir($path . $filename . "/")) { 
23                                // Need to include full "path" or it's an infinite loop 
24                if($recursive) $result[] = file_array($path . $filename . "/", $exclude, true); 
25            } else { 
26                if ( fopen_utf8($path . $filename) ) 
27                { 
28                    //$result[] = $filename; 
29                    echo ($path . $filename . "<br>"); 
30                } 
31            } 
32        } 
33    } 
34    return $result; 
35} 
36
37$files = file_array("."); 
38?>