Archive for January, 2010

Wordpress Plugin Google Analytics reset forever

Google Analytics Plugin for Wordpress

The google analytics plugin for wordpress is useful: it allows to insert the google analytics tracking code without any change to the theme file.

There is however something very irritating with this plugin: each time I upgraded the plugin, I had to re-enter the settings. And more frustrating: as long as you don’t update the settings, your stats are not recorded anymore by google analytics. This is why I’m almost not upgrading it anymore :-(

I got an even worst surprise after an upgrade of both worpdress and the google analytics plugin: I was unable to save the parametrs, each try ended with: Read the rest of this entry »

Search files using PHP with a mask pattern

This morning, I cam to a very, very basic need: detect whether a file matching a specific pattern (like ‘*.txt’) is available.

However, I could not find any ready to use PHP function, although PHP5 provides some interesting functions, like scandir().

After completing writting such a function, I decided to share it. So here is it.

Bare in mind it requires PHP5 (or later), as it relies on scandir() and on fnmatch(). Finally, this function while return the filtered directory content, regardless of the content being a file, a link or a directory.

Additional feature: by default, if you call the function more than once in your script in order to scan the same directory, it will read the directory only once: next times, it will use a cached content. To disable caching, set the third parameter to 1.

function searchdir( $path='.', $mask='*', $nocache=0 ){
 static $dir = array();
 if ( !isset($dir[$path]) || $nocache) {
 $dir[$path] = scandir($path);
 foreach ($dir[$path] as $i=>$entry) {
 if ($entry!='.' && $entry!='..' && fnmatch($mask, $entry) ) {
 $sdir[] = $entry;
 if ($nocache)
 return ($sdir);

Did you find this small function useful? Do you have any improvment suggestion?