简体   繁体   中英

Glob doesn't return results

I'm probably doing something wrong but I can't find what.

Here is the code that works:

foreach (glob('uploads/'.$userid.'[*') as $file)
{
  echo $file."<br>";
}

And here what I am trying to make it work but it doesn't:

foreach (glob('uploads/'.$userid.'[?]('.$id.')*') as $file)
{
  echo $file."<br>";
}

Some file examples:

uploads/24[3](30) Random name.pdf
uploads/24[1](114) Random name.pdf
uploads/24[2](55) Random name.doc
etc etc

Basically: UserID[1-3](ID) name of the file

glob function :

The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells .

you need to escape your brackets and parentheses as follows :

foreach (glob('uploads/'.$userid.'\[?\]\(' . $id . '\)*') as $file) {
    echo $file."<br />";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM