Home > Article > Backend Development > php write file
This article mainly introduces about writing files in PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
//要创建的两个文件 $TxtFileName = "Demo.txt"; //以读写方式打写指定文件,如果文件不存则创建 if( ($TxtRes=fopen ($TxtFileName,"w+")) === FALSE){ echo("创建可写文件:".$TxtFileName."失败"); exit(); } $StrConents = ''; foreach($_POST as $k=>$v){ $StrConents.=$k."=".$v."------"; } if(!fwrite ($TxtRes,$StrConents)){ //将信息写入文件 echo ("尝试向文件".$TxtFileName."写入".$StrConents."失败!"); fclose($TxtRes); exit(); } fclose ($TxtRes); //关闭指针
Related recommendations:
php writes file fwrite() function usage summary
The above is the detailed content of php write file. For more information, please follow other related articles on the PHP Chinese website!