php生成静态页面程序
模板 template.html :
复制PHP内容到剪贴板
HTML代码:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><%{title}%></title> </head> <body> <%{content}%> </body> </html>
生成 generator.php :
复制PHP内容到剪贴板
PHP代码:
<?php /* ** html静态页面生成模块 */ $title = "cShare.ORG首页"; $content = "红绿蓝(cShare.ORG)"; $template = file_get_contents("template.html"); //读取模板 $template = str_replace("<%{title}%>", $title, $template); //替换标记 $template = str_replace("<%{content}%>", $content, $template); while(!file_exists("number.txt")) { //如不存在编号文件,则创建一个并写入初始编号0 file_put_contents("number.txt",0); } $html_number = file_get_contents("number.txt"); $html_number++; file_put_contents("number.txt",$html_number); $html_name = "{$html_number}.html"; file_put_contents($html_name, $template); //生成静态页面
本文地址:http://www.phprm.com/code/09d318ed23446abfd0f1f80d46a6da16.html
转载随意,但请附上文章地址:-)