php file_put_content 如果不存在则创建文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23268249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:36:54  来源:igfitidea点击:

file_put_content create file if not exist?

php

提问by user3552670

$html = file_get_contents('http://www.test.com);
$file = '/Applications/MAMP/htdocs/test.html';
file_put_contents($file,$html);

Does file_put_content create the file test.html when file doesn't exists?

当文件不存在时,file_put_content 是否创建文件 test.html?

回答by Awlad Liton

yes.

是的。

as per php documentation:

根据php 文档

If filename does not exist, the file is created.

如果文件名不存在,则创建该文件。