douren1891 2016-09-05 01:17
浏览 62
已采纳

如果我使用通配符,glob只能拉数组

I'm trying to use glob() to find images in my folder that match a pattern. There are too many images to manually search through, so glob() seems like a good approach.

I don't seem to be able to get glob to work, however.

I have 5 images with the following patter: diamond_z_classic_397-106 but when I use glob as such:

print_r(glob("diamond_z_classic_397-106.*")); then this is what is returned array() . When I do this: pring_r(glob("*.*")); then it pulls everything from the directory included the 5 matches.

I've scanned SO as well as http://php.net/manual/en/function.glob.php and http://www.w3schools.com/php/func_filesystem_glob.asp to figure out what I'm missing.

What could be causing this, or what am I missing.

Also, is it possible to use a variable like this: glob("$pattern.*"); ?

Thanks

Update Here are the 5 exact names that should match the pattern: diamond_z_classic_397-106-100-80-100-c-rd-255-255-255.jpg

diamond_z_classic_397-106-100-80-100-c.jpg

diamond_z_classic_397-106-120-90-100-c.jpg

diamond_z_classic_397-106-300-300-100-wm-center_middle-0-ColorCountryAussies-255-255-255-35.jpg

diamond_z_classic_397-106-800-800-100-wm-center_middle-0-ColorCountryAussies-255-255-255-35.jpg

  • 写回答

2条回答 默认 最新

  • douping6871 2016-09-05 01:33
    关注

    Remove the . from your pattern, i.e. glob("diamond_z_classic_397-106*").

    With glob * alone matches zero or more of any character. You're attempting to match a literal . that doesn't exist at that place in your file names.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 能给我一些人生建议吗
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到
  • ¥15 请教一下,openwrt如何让同一usb储存设备拔插后设备符号不变?
  • ¥30 使用quartz框架进行分布式任务定时调度,启动了两个实例,但是只有一个实例参与调度,另外一个实例没有参与调度,不知道是为什么?请各位帮助看一下原因!!
  • ¥50 怎么获取Ace Editor中的python代码后怎么调用Skulpt执行代码
  • ¥30 fpga基于dds生成幅值相位频率和波形可调的容易信号发生器。
  • ¥15 R语言shiny包和ncdf4包报错
  • ¥15 origin绘制有显著差异的柱状图和聚类热图
  • ¥20 simulink实现滑模控制和pid控制对比,提现前者优势