preg match - use PHP preg_match on directory name - Unknown modifier -


can advise correct way use preg_match on directory names.

ive used glob - small array of files , wanting use preg_match on resulting foreach including directory..

however getting error - preg_match(): unknown modifier 'h' in ....

h of course 1st letter of directory after initial slash - /

edit - code ($path includes full path name)

$temp="$path/$name-$type-$number\n"; // $temp=preg_replace("/\//","\/",$temp); $files=glob("$path/$name*"); foreach($files $ab => $ac) {   $outlist.="'$ab' '$ac'\n";   $outlist.="temp '$temp'\n";   if(preg_match("/$temp/i",$ac))   {     $outlist.="got '$ac'\n";   } } 

so don't use / delimiter regex. or escape slashes in input.

if(preg_match("~$temp~i",$ac)){$outlist.="got '$ac'\n";}

assuming ~ never part of $temp

or escaping:

$temp2 = preg_quote($temp, '/'); if(preg_match("/$temp2/i",$ac)){$outlist.="got '$ac'\n";} ` 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -