php 转义 回车 空格 file put content,关于php:如何处理根文件夹路径中的空格

我在本地服务器上编写了一个PHP脚本,该脚本需要包含文件的路径,我需要在其中使用file_put_contents将内容写入文件,该文件在localhost上没有任何问题。 我将文件移动到已配置了路径的Web服务器,该路径之间有空格

例如:

C: Program File(xxx) Apache Software Foundation Apache2.2 htdocs writecode writefile

当我尝试打开文件夹writefile将内容写入该文件夹中的temp_1.cfg文件时,它弹出错误

Warning:

file_put_contents(C:\ProgramFile(xxx)\ApacheSoftwareFoundation\Apache2.2\htdocs\writtencode\writefile\temp_1.cgf)

[function.file-put-contents]: failed to open stream: No such file or

directory in C:\Program File (xxx)\Apache Software

Foundation\Apache2.2\htdocs\writtencode\writefile\index.php

使用file_put_contents将内容写入文件时,如何删除或解决路径中的空格的想法?

$path ="C:\ProgramFile(xxx)\Apache Software Foundation\Apache2.2\htdocs\writtencode\writefile\temp_1.cgf";

file_put_contents($path = str_replace(' ', '\ ', $path));

您是否尝试将路径用引号引起来?

另外,您可能需要转义所有反斜杠,这样:

file_put_content(C:\ProgramFile(xxx)\ApacheSoftwareFoundation\Apache2.2\htdocs\writtencode\writefile\temp_1.cgf);

变成:

file_put_content('C:\\ProgramFile(xxx)\\ApacheSoftwareFoundation\\Apache2.2\\htdocs\\writtencode\\writefile\\temp_1.cgf');

我已将路径括在引号中,并且需要在路径中包含空格,以便它将空格并写入正确的文件中。

好的,为方便起见,我将:subst x:"C:\Program File (xxx)\Apache Software Foundation\Apache2.2\htdocs"添加到批处理文件(例如mapx.bat)中。 运行此批处理文件,现在可以通过驱动器x访问您的htdocs文件夹:file_put_content(x:\writtencode\writefile\temp_1.cgf);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值