php如何生成html

php如何生成html,第1张

<?php

 $Html = '<html><head><title>这是一个html文档</title></head><body>这是php生成的一个html文档</body></html>'

 file_put_contents( 'abc.html', $Html )

上面代码运行后,就会生成一个abc.html文件

自己根据这个代码进行研究下!

页面静态化--------------------------------------

ob_start()

$static_file = '1.html'//静态页面

$php_file = basename(__FILE__)//当前动态页面

if (!file_exists($static_file) ||

((filemtime($static_file)+10) <time()) || //缓存固定时间

filemtime($php_file) >filemtime($static_file)) //源文件已修改

{

echo '静态页面示例'

echo 'erer'

$c = ob_get_contents()

ob_clean()

file_put_contents($static_file, $c)

}

$s = file_get_contents($static_file)

echo $s

用缓冲池

<?php

ob_start()

//你的原PHP代码

$contents = ob_get_contents()

$handle = fopen('test.html','a+')

fwrite($handle,$contents)

ob_end_clean()

?>

这样你的输出就都放在test.html文件里了,没有任何变化


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/8067456.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存