从数组中的不同文件中读取特定内容

从数组中的不同文件中读取特定内容

问题描述:

I have got different files in one directory. Each file consists the string "name_service ". The values are different. In my PHP Script I need to read the values in one array.

I found the PHP-function "file()" to read the filecontent to an array, but this seem only to work if the php-file and the files to read are in the same directory.

I need a function to read the content of a file to an array which is not in the same directory as the PHP-files.

我在一个目录中有不同的文件。 每个文件都包含字符串“name_service”。 值不同。 在我的PHP脚本中,我需要读取一个数组中的值。 p>

我发现PHP函数“file()”将文件内容读入数组,但这似乎只能工作 如果php文件和要读取的文件在同一目录中。 p>

我需要一个函数来将文件内容读取到与该目录不在同一目录中的数组中 PHP文件。 p> div>

No, it will work for any file in filesystem:

$data = file('directory/file.txt');

You should only use here correct file path.

Directory may be relative to current path and in current path (as above), or relative to current path but in other directory for example ../directory/file.txt or it can be absolute path: /usr/etc/file.txt