[英]How do I include a .php or .html file in a .html file?
說我有我的文件index.html
,我想在其中包含a.php
和b.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>
這是我的a.php
文件:
<html>
<head>
<p>
Hello there, you rock.
</p>
</head>
</html>
這是我的b.html
文件:
<html>
<head>
<p>
Hello there, you rock even more.
</p>
</head>
</html>
我需要做什么才能使index.html
與其a.php
和b.html
內容一起顯示? 目前,包含a.php
的一小部分無法正常工作,所以我想問一下。
謝謝
第一件事:將index.html
的擴展名更改為index.php
。 否則,服務器將不會知道要解析的PHP。
其次,您無需重復index.php
文件中已存在的html
, body
, head
和其他文檔標簽。 使用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>
修改a.php
文件:
<p>
Hello there, you rock.
</p>
修改后的b.php
文件:
<p>
Hello there, you rock even more.
</p>
您有三種解決方案:
將index.html
的擴展名更改為index.php
或者,您必須通過iframe
包含a.php
。
或者,您必須通過ajax
調用a.php
,然后將響應放在您想要的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.