如何处理根文件夹路径中的空格

125*_*369 1 php whitespace

我在我的本地服务器上编写了一个PHP脚本,需要包含文件的路径,我需要将文件内容写入文件,使用file_put_contents该文件在localhost上没有任何问题.我将文件移动到网络服务器,在网络服务器中配置了路径,其间有空格,例如:C:\ Program File(xxx)\ Apache Software Foundation\Apache2.2\htdocs\writtencode\writefile \

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

警告:file_put_contents(C:\ ProgramFile(xxx)\ ApacheSoftwareFoundation\Apache2.2\htdocs\writtencode\writefile\temp_1.cgf)[function.file-put-contents]:无法打开流:C中没有这样的文件或目录:\ Program File(xxx)\ Apache Software Foundation\Apache2.2\htdocs\writtencode\writefile\index.php

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

Nik*_*luk 5

$path ="C:\ProgramFile(xxx)\Apache Software Foundation\Apache2.2\htdocs\writtencode\writefile\temp_1.cgf";
file_put_contents($path = str_replace(' ', '\ ', $path));
Run Code Online (Sandbox Code Playgroud)