Php glob
Contents |
PHP function glob
This function returns a matched list as an array based on a specific pattern.
Syntax glob
- pattern: a string match pattern
- flags: sets rule for the match
glob(pattern, flags);
Flags
- GLOB_MARK - Adds a slash to each directory returned
- GLOB_NOSORT - Return files as they appear in the directory (no sorting)
- GLOB_NOCHECK - Return the search pattern if no files matching it were found
- GLOB_NOESCAPE - Backslashes do not quote metacharacters
- GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'
- GLOB_ONLYDIR - Return only directory entries which match the pattern
- GLOB_ERR - Stop on read errors (like unreadable directories), by default errors are ignored.
Note
Example 1
<?php print_r(glob("*.php")); ?>
Output
These are the files in the current directory.
Array ( [0] => fileinode.php [1] => filemtime.php [2] => fileowner.php [3] => fileperms.php [4] => filesize.php [5] => filetype.php [6] => flock2.php [7] => glob.php [8] => is_write.php [9] => tempnam.php [10] => tmpfile.php [11] => touch.php [12] => umask.php [13] => umask2.php )
Example 2
<?php print_r(glob("/home/abc/*.csv")); ?>
Related Links
basename-- chgrp-- chmod-- chown-- clearstatcache-- copy-- delete-- dirname-- disk_free_space-- disk_total_space-- diskfreespace-- fclose-- feof-- fflush-- fgetc-- fgetcsv-- fgets-- fgetss-- file_exists-- file_get_contents-- file_put_contents- file-- fileatime-- filectime-- filegroup-- fileinode-- filemtime-- fileowner-- fileperms-- filesize-- filetype-- flock-- fnmatch-- fopen-- fpassthru-- fputcsv-- fputs-- fread-- fscanf-- fseek-- fstat-- ftell-- ftruncate-- fwrite-- glob-- is_dir-- is_executable-- is_file-- is_link-- is_readable-- is_uploaded_file-- is_writable-- is_writeable-- lchgrp-- lchown-- link-- linkinfo-- lstat-- mkdir-- move_uploaded_file-- parse_ini_file-- parse_ini_string-- pathinfo-- pclose-- popen-- readfile-- readlink-- realpath_cache_get-- realpath_cache_size-- realpath-- rename-- rewind-- rmdir-- set_file_buffer-- stat-- symlink-- tempnam-- tmpfile-- touch-- umask-- unlink--