html中插入php的方法

html中插入php的方法,第1张

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

?>

如果想要跳转到另外一个html文件,需要有以下几步:

找到你要跳转的html文件的路径地址,如果是你本机上的某个文件,路径url就是相对你当前文件的路径,类似于:../../test/a/b/c.html,这是相对路径,也可以填写绝对路径,如果是网络上的某个html文件,就填写http开头的具体文件路径url就好了

在你当前文件中最后加上如下代码:Header("Location:$url")   $url就是第一点中说的路径url。

如果觉得有用请点赞并关注下,感谢!


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

原文地址:https://54852.com/sjk/6717870.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存