Home > Backend Development > PHP Tutorial > php文件操作基本用法

php文件操作基本用法

WBOY
Release: 2016-06-23 13:45:00
Original
974 people have browsed it

<?php /* $fp=fopen("tmp.html","r"); $str=fread($fp,filesize("tmp.html")); $str=str_replace("{title}",'新标题',$str); $str=str_replace("{content}",'新内容',$str);fclose($fp);$handle=fopen('new.html','w');fwrite($handle,$str);fclose($handle);echo "<br>生成成功!";*/  $con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2'),array('新闻标题3','新闻内容3'));  foreach($con as $id=>$val){  $title=$val[0];  $content=$val[1];  $path=$id.'.htm';  $fp=fopen("tmp.html","r"); //只读打开模板  $str=fread($fp,filesize("tmp.html"));//读取模板中内容  $str=str_replace("{title}",$title,$str);  $str=str_replace("{content}",$content,$str);//替换内容  fclose($fp);  $handle=fopen($path,"w"); //写入方式打开新闻路径  fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件  fclose($handle);  echo "生成成功";  }  if(unlink('1.htm'))//删除文件  {  	echo "删除成功";  }  else{  	echo "删除失败";  };  if(mkdir('up1')){//创建文件夹  	echo "创建成功";  }  else{  	echo "创建失败";  }  if(rmdir('up1')){//删除文件夹  	echo "删除成功";  }  else{  	echo "删除失败";  }?>
Copy after login

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