php write file

不言
Release: 2023-03-25 18:24:01
Original
3597 people have browsed it

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); //关闭指针
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template