1 | <?php |
||
2 | |||
3 | //Set Source Path |
||
4 | $sourcepath = "/var/www/put/your/path/here"; |
||
5 | |||
6 | //Regex Express to test leading and trailing spaces |
||
7 | define("PRE", "#^[\n\r|\n\r|\n|\r|\s]+<\?php#"); |
||
8 | define("POST", "#\?>[\n\r|\n\r|\n|\r|\s]+$#"); |
||
9 | |||
10 | clearstatcache(); |
||
11 | |||
12 | $root = ereg_replace("/$", "", ereg_replace("[\\]", "/", $sourcepath)); |
||
0 ignored issues
–
show
|
|||
13 | |||
14 | if (false === m_walk_dir($root, "check", true)) { |
||
15 | echo "‘{$root}’ is not a valid directory\n"; |
||
16 | } |
||
17 | |||
18 | |||
19 | function m_walk_dir($root, $callback, $recursive = true) |
||
20 | { |
||
21 | $dh = @opendir($root); |
||
22 | if (false === $dh) { |
||
23 | return false; |
||
24 | } |
||
25 | while ($file = readdir($dh)) { |
||
26 | if ("." == $file || ".." == $file || "framework" == $file) { |
||
27 | continue; |
||
28 | } |
||
29 | call_user_func($callback, "{$root}/{$file}"); |
||
30 | if (false !== $recursive && is_dir("{$root}/{$file}")) { |
||
31 | m_walk_dir("{$root}/{$file}", $callback, $recursive); |
||
32 | } |
||
33 | } |
||
34 | closedir($dh); |
||
35 | return true; |
||
36 | } |
||
37 | |||
38 | |||
39 | function check($path) |
||
40 | { |
||
41 | if (!is_dir($path)) { |
||
42 | $fh = file_get_contents($path); |
||
43 | if (preg_match(PRE, $fh)) { |
||
44 | echo $path. " — contains leading spaces \n"; |
||
45 | } |
||
46 | if (preg_match(POST, $fh)) { |
||
47 | echo $path . " — contains trailing spaces \n"; |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.