Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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 检查文件夹中包含使用glob()的模式的文件名_Php_File_Glob_Dir - Fatal编程技术网

Php 检查文件夹中包含使用glob()的模式的文件名

Php 检查文件夹中包含使用glob()的模式的文件名,php,file,glob,dir,Php,File,Glob,Dir,我需要检查文件夹中包含'.符号的文件。我使用了glob函数从服务器位置获取文件。但我不知道是否检查文件名中包含符号的任何位置。 我有如下格式的文件名学生178年级1A 我是这样做的 $report_files=glob( '/user_uploads/' . '/reportcards/' . 'term' . '_' . 10.'/*'.'.pdf' ); //this will return all files inside the folder. if(count(report_fi

我需要检查文件夹中包含
'.
符号的文件。我使用了glob函数从服务器位置获取文件。但我不知道是否检查文件名中包含符号的任何位置。 我有如下格式的文件名<代码>学生178年级1A

我是这样做的

$report_files=glob( '/user_uploads/'  . '/reportcards/' . 'term' . '_' . 10.'/*'.'.pdf' );

//this will return all files inside the folder.

if(count(report_files)>0)
 {
        //some stuff
 }
 else
 {

 }
我需要获取文件名中包含“\”的文件。我尝试了

glob( '/user_uploads/'  . '/reportcards/' . 'term' . '_' . 10.'/*[_]'.'.pdf' );

但它不起作用

首先,学期结束后你忘了带引号

$report_files = glob('/user_uploads/'.'/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');
其次,在
user\u上传后有两个斜杠

$report_files = glob('/user_uploads/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');

首先,学期结束后你忘了带引号

$report_files = glob('/user_uploads/'.'/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');
其次,在
user\u上传后有两个斜杠

$report_files = glob('/user_uploads/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');

您的正则表达式似乎不正确。这可能会满足您的要求:

// Find any file in the directory "/user_uploads/reportcards/term_10/" 
// that has the file extension ".pdf"
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\.pdf");

// Find any file in the directory "/user_uploads/reportcards/term_10/" 
// containing the character "_".
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)");

// Find any file in the directory "/user_uploads/reportcards/term_10/" 
// that has the file extension ".pdf" and contains the "_" character
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)\.pdf");
如果您不完全理解正则表达式的作用,我将在下面简要介绍一下所做的工作。还有一个很好的网站可以试用常规的expresson,并提供关于如何构建它们的文档


您的正则表达式似乎不正确。这可能会满足您的要求:

// Find any file in the directory "/user_uploads/reportcards/term_10/" 
// that has the file extension ".pdf"
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\.pdf");

// Find any file in the directory "/user_uploads/reportcards/term_10/" 
// containing the character "_".
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)");

// Find any file in the directory "/user_uploads/reportcards/term_10/" 
// that has the file extension ".pdf" and contains the "_" character
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)\.pdf");
如果您不完全理解正则表达式的作用,我将在下面简要介绍一下所做的工作。还有一个很好的网站可以试用常规的expresson,并提供关于如何构建它们的文档


我忘记为问题中的术语添加四分之一标记。我需要筛选其中包含下划线的文件名。我忘记为问题中的术语添加四分之一标记。我需要筛选其中包含下划线的文件名。我使用了$report\u files=glob(“\/user\u uploads\/reportcards\/term\u 10”“/*”。“'.'.'.'.'.'.'.'.'.pdf'”;//这对我很有用。谢谢你给我这个主意。我使用了$report\u files=glob(“\/user\u uploads\/reportcards\/term\u 10”“/*”);//这对我很有用。谢谢你给我这个主意。