use PHP preg_match on directory name – Unknown modifier

Home / Uncategorized / use PHP preg_match on directory name – Unknown modifier

can anyone advise the correct way to use preg_match on directory names.

Ive used glob – to get a small array of files and I am wanting to use preg_match on the resulting foreach INCLUDING the directory..

however I am getting this error – preg_match(): Unknown modifier ‘h’ in ….

H of course is the 1st letter of my directory after the initial slash – /

EDIT – Code ($path includes the full path name)
// $temp=preg_replace("///","/",$temp);
foreach($files as $ab => $ac)
$outlist.="’$ab’ ‘$ac’n";
$outlist.="TEMP ‘$temp’n";
$outlist.="GOT ‘$ac’n";

so don’t use the / as the delimiter for your regex. Or escape the slashes in your input.

if(preg_match("~$temp~i",$ac)){$outlist.="GOT ‘$ac’n";}

assuming the ~ is never part of $temp

or by escaping:$temp2 = preg_quote($temp, ‘/’);
if(preg_match("/$temp2/i",$ac)){$outlist.="GOT ‘$ac’n";} `
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *