Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php fwrite if text not';文件中不存在吗?_Php_Symfony4 - Fatal编程技术网

Php fwrite if text not';文件中不存在吗?

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

如果文本不存在,如何在文件中写入文本;如果文本已经存在,如何继续写入文本的其他部分。 我还必须在某些条件下删除文本(如果$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('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);