Created
January 9, 2017 12:55
-
-
Save Balamir/ee9d33687fb3b32f32605f28e3496983 to your computer and use it in GitHub Desktop.
PHP glob() with path contains brackets "[" and "]"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * glob() does not normally work if the path contains brackets "[" and "]". | |
| * For example, this will make it fail: | |
| * $files = glob("[myfolder]/*.txt"); | |
| * No error is returned, just an empty array! | |
| * We need to replace that brackets with [] prefix and [] suffix. | |
| * $files = glob("[[]myfolder[]]/*.txt"); | |
| * ta da.. | |
| **/ | |
| function sd_glob( $path ) { | |
| $path = str_replace( array( ']', '[' ), array( '[]]', '[[]' ), $path ); | |
| return glob( $path ); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment