我想在文本文件中获取内容,而我正在使用file_get_contents()
但是当我尝试将具有空格的文件读入文件名时,问题就开始了。
例如:使用/home/project/text cv.txt
无法读取file_get_contents()
。
是否有读取.txt文件的替代方法?
答案 0 :(得分:3)
文档中有一个提示:
If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().
答案 1 :(得分:2)
另一种选择是使用realpath()将URI包装到您的文件中:
$path = realpath( dirname(__FILE__).'/../_files/file with space.txt' );
$data = file_get_contents($path);
答案 2 :(得分:0)
尝试file_get_contents(text cv);
或file_get_contents(text%20cv);