簡體   English   中英

如何在.html文件中包含.php或.html文件?

[英]How do I include a .php or .html file in a .html file?

說我有我的文件index.html ,我想在其中包含a.phpb.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.phpb.html內容一起顯示? 目前,包含a.php的一小部分無法正常工作,所以我想問一下。

謝謝

第一件事:將index.html的擴展名更改為index.php 否則,服務器將不會知道要解析的PHP。

其次,您無需重復index.php文件中已存在的htmlbodyhead和其他文檔標簽。 使用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>

您有三種解決方案:

  1. index.html的擴展名更改為index.php

  2. 或者,您必須通過iframe包含a.php

  3. 或者,您必須通過ajax調用a.php ,然后將響應放在您想要的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM