如何在PHP中嵌入一个HTML文件

html-css010

如何在PHP中嵌入一个HTML文件,第1张

php里面添加html文件,很多时候需要用到!

如添加一个站点统计到网站,如果你的网站全部是php来写的,这时候直接用echo输出统计代码就会出现问题!然后php可以很方便的引入一个html文件,这样就方便多了!

具体操作如下:

在do_footer函数里面利用include即可导入一个html文件

1)修改do_footer函数

function do_footer($credits = true) {

global $globals

echo "</div<!–#container closed–\n"

include("hugwww-footer.html")

if($credits) @do_credits()

do_js_from_array($globals['post_js'])

// warn warn warn

// dont do stats of password recovering pages

@include(‘ads/stats.inc’)

printf("\n<!–Generated in %4.3f seconds–\n", microtime(true) – $globals['start_time'])

2)将统计代码写入hugwww-footer.html文件完成!

PHP写入HTML文件可以使用file_put_contents,例如:

file_put_contents('a.html', "<html>

<body>hello</body>

</html>")

PHP访问HTML文件可以使用readfile、file等,例如:

readfile('a.html')