note 83263 added to function.glob

From: Date: Sat, 17 May 2008 20:38:40 +0000
Subject: note 83263 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-139467@lists.php.net to get a copy of this message
You should use preg_quote every time you want to add a path to an directory. Use it like this: <?php $dir = './mydir/[with]/special/.chars/'; $file = '[a-z]+\.txt'; $files = glob( preg_quote( $dir, DIRECTORY_SEPARATOR ) . $file ); if($files !== false && count($files) != 0) { // Do something with the files } ?> Reason: Special chars like [ or . will match in regular expressions so "/dir/[special]/*.txt" will match on all files in the dirs /dir/s/, /dir/p/, /dir/e/, /dir/c/, /dir/i/, /dir/a/, /dir/l/ I hope i could help. MFG Miah :) ---- Server IP: 217.13.201.10 Probable Submitter: 79.221.195.157 ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- https://master.php.net/note/edit/83263 Del: integrated -- https://master.php.net/note/delete/83263/integrated Del: useless -- https://master.php.net/note/delete/83263/useless Del: bad code -- https://master.php.net/note/delete/83263/bad+code Del: spam -- https://master.php.net/note/delete/83263/spam Del: non-english -- https://master.php.net/note/delete/83263/non-english Del: in docs -- https://master.php.net/note/delete/83263/in+docs Del: other reasons-- https://master.php.net/note/delete/83263 Reject -- https://master.php.net/note/reject/83263 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139467) next »