PHP foreach glob多个扩展 [英] php foreach glob multiple extensions

查看:203
本文介绍了PHP foreach glob多个扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php $ imagecounter =no; 
foreach(glob(images / *。jpg)as $ image){
$ imagecounter =yes;

foreach(glob(images / *。png)as $ image){
$ imagecounter =yes;
}
foreach(glob(images / * .gif)as $ image){
$ imagecounter =yes;
}
if($ imagecounter ==yes){Create gallery}?>

该文件夹可能有zip或pdf文件,不能创建图库

$ b如果(glob(images / *。{jpg,png,gif},GLOB_BRACE))$($ b $ div class =h2_lin>解决方案

  b $ b {
//创建图库
}

就是这样:)

There has got to be a better way to write this:

<?php $imagecounter = "no";
    foreach (glob("images/*.jpg") as $image)    {
    $imagecounter = "yes";
    }
    foreach (glob("images/*.png") as $image)    {
    $imagecounter = "yes";
    }
    foreach (glob("images/*.gif") as $image)    {
    $imagecounter = "yes";
    }
    if ($imagecounter == "yes"){Create gallery}?>

That folder might have zip or pdf files too that should not create a gallery

解决方案

if(glob("images/*.{jpg,png,gif}", GLOB_BRACE))
{
  //create gallery
}

And that's about it :)

这篇关于PHP foreach glob多个扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆