设置example.html为模板文件,然后按照此模板文件生成article-1.html~article-5.html,以此来做简单的演示,代码如下:

<?php//将数据存入二维数组$con=array(array('文章标题1','文章内容1'),array('文章标题2','文章内容2'),array('文章标题3','文章内容3'),array('文章标题4','文章内容4'),array('文章标题5','文章内容5'));foreach($con as $id=>$val){ //循环生成

$title=$val[0]; $content=$val[1]; $path="article-".($id+1).".html"; //替换example内容,并获取内容赋值给$str

$fp=fopen("example.html","r"); $str=fread($fp,filesize("example.html")); $str=str_replace("{title}",$title,$str); $str=str_replace("{content}",$content,$str);

fclose($fp); //新建空白文件,将$str写入

$handle=fopen($path,"w");

fwrite($handle,$str);

fclose($handle); echo "生成".$path."<br/>";

}?>}

注解:

fopen(文件名,打开方式),打开文件函数,若无文件,则创建。其返回值为资源型;

fread(文件名,读取字节数),读取文件内容及对应的字节数;

str_replace(规定要查找的值,替换被查找值的值,被搜索的字符串),替换函数;

fclose(文件名),关闭文件;

fwrite(要写入的打开文件,要写入打开文件的字符串,要写入的最大字节数)。

Andreas Creten explains his view on wether you should always try to write perfect code. Spoiler: no.

The engineers want to write perfect code using the latest techniques, make sure that the code is well documented so they can fully understand how everything works and that it has tests so they can easily update things later. Product owners on the other hand just want things to be done, fast and cheap, so they can ship new features or convince new clients.

How can you make these conflicting views work together?

https://medium.com/we-are-madewithlove/does-code-need-to-be-perfect-a53f36ad7163

Freek Van der Herten

Freek Van der Herten is a partner and developer at Spatie , an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modernphp and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band .

最新文章

  1. 趣谈、浅析CRLF和LF
  2. HTML概况性介绍
  3. MVVM框架思想
  4. 简单讲解iOS应用开发中的MD5加密的相关使用&lt;转&gt;
  5. 底层restful接口修改分析
  6. 设计模式六大原则(2):里氏替换原则(Liskov Substitution Principle)
  7. Cocos2d-x 3.0final 终结者系列教程12-Vector&amp;amp;map&amp;amp;value
  8. Win7和Ubuntu下mysql 安装配置
  9. 自动化利器-Zabbix
  10. 【注意事项】APP左右横滑设计
  11. CSS样式之选择器
  12. Android Studio 自动生成 Java Doc
  13. Java Proxy和CGLIB动态代理原理
  14. BZOJ_3238_[Ahoi2013]差异_后缀自动机
  15. 网工的Linux系统学习历程
  16. UVALive - 4225(贪心)
  17. Study 1 —— Python简介
  18. JDK8下maven使用maven-javadoc-plugin插件报错
  19. SDUT 1269-走迷宫(DFS打印路径)
  20. [py]python的继承体系

热门文章

  1. 理解最短路径-Dijkstra算法
  2. UITableViewHeaderFooterView can&#39;t change custom background when loading from nib
  3. myeclipse 配置resin
  4. Vue 获取dom元素之 ref 和 $refs 详解
  5. 基于TensorFlow理解CNN中的padding参数
  6. Mybatis编写初始化Dao代码
  7. http协议与servletl理解
  8. Django部署,Django+uWSGI+nginx+Centos部署
  9. mybatis学习:mybatis的环境搭建与入门
  10. 跟我一起做一个vue的小项目(十一)