袁来如此的工作笔记
袁来如此的工作笔记
竹杖芒鞋轻胜马,谁怕? 一蓑烟雨任平生。

PHP实现静态化方法

浏览量:240

what:

why:

how:
//如果存在这个文件并且最近修改时间来判断是否生成静态文件
if(is_file(\index.html\)&&(time()-filemtime(\index.html\))<300){
	//显示
	require_once(\index.html\);
}else{
	//生成且显示


	$connect = new mysqli(\localhost\,\root\,\\,\edu\);
	//设置字符集
	$sql = "  from user ";

	$result = $connect->query($sql);

	while($row = $result->fetch_assoc()){

		$list[]= $row;

	}


	ob_start();
	require_once(\static.html\);//模板文件

	

	file_put_conents(\index.html\,ob_get_contents());
}

打赏