2 /* Prototype: array glob ( string $pattern [, int $flags] );
3 Description: Find pathnames matching a pattern
6 echo "*** Testing glob() : usage variations ***\n";
8 $file_path = dirname(__FILE__
);
11 mkdir("$file_path/glob_variation");
12 mkdir("$file_path/glob_variation/wonder");
15 $fp = fopen("$file_path/glob_variation/wonder12345", "w");
17 $fp = fopen("$file_path/glob_variation/wonder;123456", "w");
21 "$file_path/glob_variation/*der*",
22 "$file_path/glob_variation/?onder*",
23 "$file_path/glob_variation/w*der?*",
24 "$file_path/glob_variation/*der5",
25 "$file_path/glob_variation/??onder*",
26 "$file_path/glob_variation/***der***",
27 "$file_path/glob_variation/++onder*",
28 "$file_path/glob_variation/WONDER5\0",
29 '$file_path/glob_variation/wonder5',
30 "$file_path/glob_variation/?wonder?",
31 "$file_path/glob_variation/wonder?",
35 /* loop through $patterns to match each $pattern with the files created
37 foreach($patterns as $pattern) {
38 echo "\n-- Iteration $counter --\n";
39 var_dump( glob($pattern) ); // default arguments
40 var_dump( glob($pattern, GLOB_MARK
) );
41 var_dump( glob($pattern, GLOB_NOSORT
) );
42 var_dump( glob($pattern, GLOB_NOCHECK
) );
43 var_dump( glob($pattern, GLOB_NOESCAPE
) );
44 var_dump( glob($pattern, GLOB_ERR
) );
48 echo "\n*** Testing glob() with pattern within braces ***\n";
49 var_dump( glob("$file_path/glob_variation/*{5}", GLOB_BRACE
) );
51 // delete temp files and dir
52 unlink("$file_path/glob_variation/wonder12345");
53 unlink("$file_path/glob_variation/wonder;123456");
54 rmdir("$file_path/glob_variation/wonder");
55 rmdir("$file_path/glob_variation");
57 echo "\n*** Testing glob() on directories ***\n";
58 // temp dir created to check for pattern matching the sub dir created in it
59 mkdir("$file_path/glob_variation/wonder1/wonder2", 0777, true);
62 /* loop through $patterns to match each $pattern with the directories created
64 foreach($patterns as $pattern) {
65 echo "-- Iteration $counter --\n";
66 var_dump( glob($pattern, GLOB_ONLYDIR
) );
72 $file_path = dirname(__FILE__
);
73 rmdir("$file_path/glob_variation/wonder1/wonder2");
74 rmdir("$file_path/glob_variation/wonder1/");
75 rmdir("$file_path/glob_variation/");