php - 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...'); 谢谢
解决方案
$word = "abc";
$file = $word . '.txt'; //for having "abc.txt"
file_put_contents($file,'content content...');
“abc”已经在变量中,然后添加“.txt”;
推荐阅读
- python - pygame不注册键输入
- javascript - 未处理的承诺拒绝:错误:无权使用后台定位服务
- postman - 表单参数“我的密钥”,文件加载错误:缺少文件源 - 邮递员
- ios - 具有透明背景的 iOS 扩展
- python - Pandas datframe excel错误
- python - 尝试解释 XGBoost 分类器的权重时出现 TypeError
- java - java - 如何接收通过Node-red发送到Java中的Reactor UdpClient / UdpServer的udp数据包?
- c# - MongoDB不会让我保存对象可能的循环引用
- npm - npm 详细堆栈错误:无法验证,需要:基本领域 =“https://npm.fontawesome.com/”,服务 =“npm.fontawesome.com”
- javascript - SharePoint Online API - 检测 NoScript (DenyAddAndCustomizePages) 状态?