Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:preg_match函数不工作?_Php - Fatal编程技术网

PHP:preg_match函数不工作?

PHP:preg_match函数不工作?,php,Php,我有文件类型 $file_type = image/png if (!preg_match("/jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF/", $file_type)) { die('Apologies, file type error'); } 如果文件类型在给定的模式中不匹配,它将给出如上所示的模具。现在,即使模式中包含文件类型,也没有匹配 按钮行是,如果文件类型不正确,我需要死亡,否则继续。对我来说很好: <?php $file_type

我有文件类型

$file_type = image/png 

if (!preg_match("/jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF/", $file_type)) {
     die('Apologies, file type error');
}
如果文件类型在给定的模式中不匹配,它将给出如上所示的模具。现在,即使模式中包含文件类型,也没有匹配

按钮行是,如果文件类型不正确,我需要死亡,否则继续。

对我来说很好:
<?php

$file_type = "image/png"; 

if (!preg_match("#image/(?:png|jpg|webp|gif)#io", $file_type)) {
    die('Apologies, file type error');
}
//if match file_type continue,