PHP生成静态页

<?php 
header('Content-type:text/html;charset=utf-8'); 
if(!function_exists('file_get_contents')){ //如果系统没有file_get_contents()函数 
function file_get_contents($file){ //自己写file_get_contents()函数 
$fp = fopen($file,'r'); 
$content = fread($fp,filesize($file)); 
fclose($fp); 
return $content; 


$tmp_file = 'template.html'; //模板文件 
$content = file_get_contents($tmp_file); //获得模板文件内容 
$title = 'title'; //模板变量title要替换的值 
$text = 'text'; //模板变量text要替换的值 
$content = str_replace('<{title}>',$title,$content); //替换模板变量title 
$content = str_replace('<{text}>',$text,$content); //替换模板变量text 
//echo $content; //显示替换后的模板文件内容 
MakeHtml('news.html',$content);//写入生成后的静态文件内容到news.html文件 
echo '<a href="news.html" target="_blank">查看文件</a>'; 
function MakeHtml($file,$content){ 
$fp = fopen($file,'w'); 
fwrite($fp,$content); 
fclose($fp); 

?> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值