php如何结合html调用数据?

html-css018

php如何结合html调用数据?,第1张

在html中调用php内容,可以用<script src="friendlinks.php"></script>然后在friendlinks.php中调取数据库数据。并输出适当的html,或者输出xml、json都可以,只是图简单的话,只要输出html就行了。

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

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

<body>hello</body>

</html>")

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

readfile('a.html')

html表单最基本的形式是form中设置action属性(数据提交路径)method表示提交数据的类型(get和post)。使用这种方式提交表单,表单元素必须设置name属性。

表单中设置这两个属性就可以获得表单的值了。

例如:

<form action="index.php" method="post">

    <input type="text" name="user" />

    <input type="submit" value="提交" />

</form> <?php

//post接收表单传过来的值

$user=$_POST['user']

echo $user

?>