如何读取文件名之间有空格的文本文件的内容


how to read the content of text files having white space between file name?

我想获取文本文件中的内容,我正在使用file_get_contents()

但是当我尝试在文件名中读取有空格的文件时,问题就开始了。

例如:/home/project/text cv.txt不能使用 file_get_contents() 读取。

有没有其他方法可以读取.txt文件?

文档中有一个提示: If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().

另一种选择是使用 realpath() 将 URI 包装到您的文件中:

$path = realpath( dirname(__FILE__).'/../_files/file with space.txt' );
$data = file_get_contents($path);

尝试file_get_contents(text cv);file_get_contents(text%20cv);