[英]How do I include a .php or .html file in a .html file?
Say I have my file index.html
, and I want to include a.php
and b.html
in them. 说我有我的文件
index.html
,我想在其中包含a.php
和b.html
。 How exactly will I go by doing this? 我将如何做呢?
Here's what I got in index.html
: 这是我在
index.html
得到的:
<!DOCTYPE html>
<html>
<head>
<title>SQL DB Demo</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
<!--Changes -->
<?php
include 'a.php';
?>
</body>
</html>
Here's my a.php
file: 这是我的
a.php
文件:
<html>
<head>
<p>
Hello there, you rock.
</p>
</head>
</html>
And here's my b.html
file: 这是我的
b.html
文件:
<html>
<head>
<p>
Hello there, you rock even more.
</p>
</head>
</html>
What do I need to do to get index.html
to display its contents along with the contents of a.php
and b.html
? 我需要做什么才能使
index.html
与其a.php
和b.html
内容一起显示? Currently, the little part with include a.php
isn't working, so I thought I'd ask. 目前,包含
a.php
的一小部分无法正常工作,所以我想问一下。
Thanks 谢谢
First thing: Change the extension of index.html
to index.php
. 第一件事:将
index.html
的扩展名更改为index.php
。 Otherwise the server isn't going to know there's PHP to be parsed. 否则,服务器将不会知道要解析的PHP。
Second, you don't need to repeat the html
, body
, head
and other document tags that are already in the index.php
file. 其次,您无需重复
index.php
文件中已存在的html
, body
, head
和其他文档标签。 With the includes, you're inserting data into that file, not creating new documents. 使用includes,您可以将数据插入到该文件中,而不是创建新文档。
<!DOCTYPE html>
<html>
<head>
<title>SQL DB Demo</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
<!-- a.php file below -->
<p>
Hello there, you rock.
</p>
<!-- b.php file below -->
<p>
Hello there, you rock even more.
</p>
</body>
</html>
Revised a.php
file: 修改
a.php
文件:
<p>
Hello there, you rock.
</p>
Revised b.php
file: 修改后的
b.php
文件:
<p>
Hello there, you rock even more.
</p>
You have three solutions : 您有三种解决方案:
change the extension of index.html
to index.php
将
index.html
的扩展名更改为index.php
OR you have to include a.php
via iframe
. 或者,您必须通过
iframe
包含a.php
。
OR you have to call a.php
via ajax
and then put response where u want. 或者,您必须通过
ajax
调用a.php
,然后将响应放在您想要的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.