服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|编程技术|正则表达式|

服务器之家 - 编程语言 - PHP教程 - PHP生成静态HTML页面最简单方法示例

PHP生成静态HTML页面最简单方法示例

2020-09-17 16:35PHP教程网 PHP教程

这篇文章主要介绍了PHP生成静态HTML页面最简单方法示例,本文使用模板替换的方法生成HTML页面,是最通用的方法,需要的朋友可以参考下

PHP文件名:dome.php

复制代码 代码如下:

<?php
    $string = 1;
    ob_start();
    @readfile("templets/list.html");
    $text = ob_get_flush();
    $myfile = fopen("list.html","w");
    $text = str_replace ("{counent}",$string,$text);
    fwrite($myfile,$text);
    ob_clean();
    ?>


模板文件名:templets/list.html

复制代码 代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

 

</body>
<table width="500" border="0" cellpadding="5" cellspacing="1" align="center" bgcolor="#add3ef">
  <tr bgcolor="#eff3ff">
    <td>用户:{counent_user}  标题:{counent_title}  发布时间:{counent_lastdate}</td>
  </tr>
  <tr bgcolor="#fff">
    <td>内容:{counent_content}</td>
  </tr>
</table>
</form>
</html>

 

延伸 · 阅读

精彩推荐