PHP check value against multiple values with OR-operator

前端 未结 3 625
失恋的感觉
失恋的感觉 2020-11-30 13:11

I have a filename($fname) and I need to assign $pClass to the file type with a \"-\" afterwards. Currently I always get text-, no matt

3条回答
  •  醉酒成梦
    2020-11-30 13:54

    I would simply change it to something like this:

    //This gets the extention for the file and assigns the class to the icon 
    $pieces = explode('.', $fname);
    $ext = array_pop($pieces);
    if(in_array($ext,array('txt','rtf','log','docx'))){
        $pClass = 'text-';
    }elseif(in_array($ext,array('zip','sitx','7z','rar','gz'))){
        $pClass = 'archive-';
    }elseif(in_array($ext,array('php','css','html','c','cs','java','js','xml','htm','asp'))) {
        $pClass = 'code-';
    }elseif(in_array($ext,array('png','bmp','dds','gif','jpg','psd','pspimage','tga','svg'))){
        $pClass = 'image-';
    }else {
        $pClass = '';
    }
    

提交回复
热议问题