Php fwrite if text not';文件中不存在吗?
如果文本不存在,如何在文件中写入文本;如果文本已经存在,如何继续写入文本的其他部分。 我还必须在某些条件下删除文本(如果$data['y']从1传递到0) 多谢各位Php fwrite if text not';文件中不存在吗?,php,symfony4,Php,Symfony4,如果文本不存在,如何在文件中写入文本;如果文本已经存在,如何继续写入文本的其他部分。 我还必须在某些条件下删除文本(如果$data['y']从1传递到0) 多谢各位 foreach ($x['data1']['alarms2'] as $data){ if ($data['y']==1){ $new_file= "test.txt"; $file = fopen($new_file, 'w') or die('Cann
foreach ($x['data1']['alarms2'] as $data){
if ($data['y']==1){
$new_file= "test.txt";
$file = fopen($new_file, 'w') or die('Cannot open file: '.$my_file);
fwrite($file, '....');
fclose($file);
}
}
使用“a+”修改器而不是“w”:
如果我使用它来不重写相同的内容,但是对于delete if条件传递到0,如何做?@M.elabdallah那么使用模式
w
或a+
,这取决于$data['y']
包含的内容…?@misorude data包含一个值为1或1的y0@M.elabdallah是的,我知道,你在最初的问题中已经说过了。我只是想告诉你该怎么做。
$new_file= "test.txt";
$file = fopen($new_file, 'a+') or die('Cannot open file: '.$my_file);
fwrite($file, '....');
fclose($file);