php插入html文件

html-css08

php插入html文件,第1张

PHP插入或者引入外部文件的函数有:require,require_once,include,include_once等;插入HTML文件使用其中任意一个函数都可以;

比如zhidao.php要插入zd.html文件,示例如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html charset=UTF-8">

<title>HTML</title>

</head>

<body>

<font  color="red">html部分</font>

</body>

</html> <?php

echo "-----------插入的HTML内容如下----------------"

echo "<br/>"

require  'test.html'

?>

运行效果如下:

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文件完成!

1、第一种是在HTML中加PHP。

<head>

<metahttp-equiv="Content-Type"content="text/htmlcharset=utf-8"/>

<metahttp-equiv="Content-Language"content="zh-CN"/>

<title>HelloWorld</title>

</head>

<body>

<?php

echo"Helloworld!这是正文"

?>

</body>

</html>

2、第二种用echo输出HTML。

因为HTML有的元素中有双引号,所以用echo输出的内容用单引号括起来,避免出错,也省了转义这一步。比如这样的代码:

<?php

if(!$_POST){

echo‘<formaction=""method="post">

服务器地址:<inputtype="text"name="host"value="localhost"/><br/>

数据库账号:<inputtype="text"name="user"value=""/><br/>

数据库密码:<inputtype="password"name="pwd"value=""/><br/>

指定数据库:<inputtype="text"name="db"value="test"/><br/>

<inputtype="submit"value="确定"/>

</form>‘

}

?>

3、第三种就是用(<<<)标记符了,这是在PHP168的模板代码中首次见到的。

<?php

print<<<EOT

<divclass="slidecont">{$label[deepblue_mainslide]}</div>

<divclass="newcontainter">

<divclass="head">{$label[deepblue_mainh1]}</div>

<divclass="cont"id="Tab1">{$label[deepblue_maint1]}</div>

<divclass="cont"id="Tab2">{$label[deepblue_maint2]}</div>

</div>

<ahref="$rs[url]"title="$rs[descrip]"target="_blank">$rs[name]</a>

EOT

?>