Home  >  Article  >  Backend Development  >  php write file

php write file

不言
不言Original
2018-05-10 09:04:413605browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn