Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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文件使用regex获取内容_Php_Regex_File Get Contents - Fatal编程技术网

PHP文件使用regex获取内容

PHP文件使用regex获取内容,php,regex,file-get-contents,Php,Regex,File Get Contents,我想用PHP打开一个带有特定正则表达式的文件。这是一个例子。我在同一文件夹中有两个文件: 20151001_Test(132489488)_Test_summary.txt 20150930_Test(132489488)_Test.txt 这两个文件位于同一文件夹中,开头的编号(20151001)正在更改。但是我想找到第二个文件,只是第一个文件的编号(132489488)。比如: $number = preg_replace('/20151001_Test\((.*)\)_test_summa

我想用PHP打开一个带有特定正则表达式的文件。这是一个例子。我在同一文件夹中有两个文件:

20151001_Test(132489488)_Test_summary.txt

20150930_Test(132489488)_Test.txt

这两个文件位于同一文件夹中,开头的编号(20151001)正在更改。但是我想找到第二个文件,只是第一个文件的编号(132489488)。比如:

$number = preg_replace('/20151001_Test\((.*)\)_test_summary.txt/','$1',$line);
$file = file_get_content('/.*_Test(' . $number . ')_test.txt/');
也许有人有答案


非常感谢

在找到要使用的文件名之前,需要先获取文件名列表

像这样的

$dir = '/your/directory/here/';
$number = preg_replace('/20151001_Test\((.*)\)_test_summary.txt/','$1',$line);
$files = scandir($dir);
$matching = preg_grep('/_Test(' . $number . ')_test.txt/');
if ($matching) {
    $file = file_get_content($matching[0]);
}

在找到要使用的文件名之前,需要先获取文件名列表

像这样的

$dir = '/your/directory/here/';
$number = preg_replace('/20151001_Test\((.*)\)_test_summary.txt/','$1',$line);
$files = scandir($dir);
$matching = preg_grep('/_Test(' . $number . ')_test.txt/');
if ($matching) {
    $file = file_get_content($matching[0]);
}

在找到要使用的文件名之前,需要先获取文件名列表

像这样的

$dir = '/your/directory/here/';
$number = preg_replace('/20151001_Test\((.*)\)_test_summary.txt/','$1',$line);
$files = scandir($dir);
$matching = preg_grep('/_Test(' . $number . ')_test.txt/');
if ($matching) {
    $file = file_get_content($matching[0]);
}

在找到要使用的文件名之前,需要先获取文件名列表

像这样的

$dir = '/your/directory/here/';
$number = preg_replace('/20151001_Test\((.*)\)_test_summary.txt/','$1',$line);
$files = scandir($dir);
$matching = preg_grep('/_Test(' . $number . ')_test.txt/');
if ($matching) {
    $file = file_get_content($matching[0]);
}

不能在
文件\u get\u content()中使用正则表达式参数;它需要一个固定的字符串文件名

如果要搜索与模式匹配的文件,则首先需要从目录中读取文件名列表。你会用这个

然后需要搜索结果数组以查找匹配的文件名。用于此的PHP函数是。这是一个正则表达式函数,您可以在这里使用正则表达式


使用上述方法找到匹配的文件名后,可以将该文件名传递到
文件\u get\u contents()
以加载文件。

不能在
文件\u get\u content()中使用正则表达式参数。
;它需要一个固定的字符串文件名

如果要搜索与模式匹配的文件,则首先需要从目录中读取文件名列表。你会用这个

然后需要搜索结果数组以查找匹配的文件名。用于此的PHP函数是。这是一个正则表达式函数,您可以在这里使用正则表达式


使用上述方法找到匹配的文件名后,可以将该文件名传递到
文件\u get\u contents()
以加载文件。

不能在
文件\u get\u content()中使用正则表达式参数。
;它需要一个固定的字符串文件名

如果要搜索与模式匹配的文件,则首先需要从目录中读取文件名列表。你会用这个

然后需要搜索结果数组以查找匹配的文件名。用于此的PHP函数是。这是一个正则表达式函数,您可以在这里使用正则表达式


使用上述方法找到匹配的文件名后,可以将该文件名传递到
文件\u get\u contents()
以加载文件。

不能在
文件\u get\u content()中使用正则表达式参数。
;它需要一个固定的字符串文件名

如果要搜索与模式匹配的文件,则首先需要从目录中读取文件名列表。你会用这个

然后需要搜索结果数组以查找匹配的文件名。用于此的PHP函数是。这是一个正则表达式函数,您可以在这里使用正则表达式


使用上述方法找到匹配的文件名后,您可以将该文件名传递到
文件\u get\u contents()
以加载文件。

您的问题是什么?您的问题是什么?您的问题是什么?您的问题是什么?谢谢!它做了我想要的,祝你有一个愉快的一天:)谢谢!它做了我想要的,祝你有一个愉快的一天:)谢谢!它做了我想要的,祝你有一个愉快的一天:)谢谢!它做了我想做的,祝你有愉快的一天:)