简体   繁体   English

Glob不返回结果

[英]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 基本上:文件的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 . glob()函数根据libc glob()函数所使用的规则搜索所有与模式匹配的路径名, 这与普通shell所使用的规则相似

you need to escape your brackets and parentheses as follows : 您需要如下转义括号和括号:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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