duanchui1251 2012-07-03 22:47
浏览 68
已采纳

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

I want to get the content in a text file and I am using file_get_contents()

But problem starts when I try to read files having white space into the file name.

for example: /home/project/text cv.txt cannot be read using file_get_contents().

Is there any alternative to read .txt files ?

  • 写回答

3条回答 默认 最新

  • dongyi2889 2012-07-03 23:10
    关注

    Another option would be to use realpath() to wrap the URI to your file:

    $path = realpath( dirname(__FILE__).'/../_files/file with space.txt' );
    $data = file_get_contents($path);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部