首页 > 解决方案 > PHP.是否可以在 file_put_contents 中使用变量?

问题描述

我想创建一个名为 abc.txt的文本文件 。所以我试试这个

$word="abc";

$file='"'.$word.".txt".'"'    //for having "abc.txt"

file_put_contents($file,'content content...'); 

我有这个错误: 警告:file_put_contents("abc.txt"): failed to open stream: Invalid argument in C:....

为什么这不起作用?我不能使用 file_put_contents(abc.txt,'content content...'); 谢谢

标签: phpvariablesfile-put-contents

解决方案


$word = "abc";

$file = $word . '.txt';    //for having "abc.txt"

file_put_contents($file,'content content...'); 

“abc”已经在变量中,然后添加“.txt”;


推荐阅读