News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jordi Boggiano's Blog:
Major glob() fail
December 07, 2009 @ 13:50:54

Jordi Boggiano had the "pleasure" of discovering a small quirk with PHP's glob function in an application he was working on - watch out for directories that contain square braces, they won't return in the results!

Working on some personal project that lists a bunch of stuff on my hard drive, I found out that directories that contain square brackets (those []) don't return any results for the simple reason that glob reads [stuff] as a character class, just like in regular expressions. When you know it it makes perfect sense, but when you don't, the documentation is really not so helpful. Of course it mentions libc's glob() and unix shells, but not everyone knows what that implies at first glance.

He tried a few things to get around the bug (including escaping the brackets in the directories) but ended up writing a function (glob_quote) to handle the escaping of all of the meta-characters glob might need to escape to return all of the files and folders correctly.

1 comment voice your opinion now!
glob fail regularexpression match


blog comments powered by Disqus

Similar Posts

Tiffany Brown's Blog: A better RegEx pattern for matching e-mail addresses

Echolibre Blog: Customising Zend Framework Routing

Refulz.com: Special characters in Regular Expressions - Part 1

Dikini.net: Rewriting macros - the peculiar case of php

The Northclick Blog: A comma is a comma is a comma...or is it?


Community Events





Don't see your event here?
Let us know!


conference voicesoftheelephpant language series podcast release zendserver community introduction bugfix api threedevsandamaybe framework code laravel deployment interview symfony tips list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework