2

Say I have my file index.html, and I want to include a.php and b.html in them. How exactly will I go by doing this?

Here's what I got in 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:

<html>
    <head>
        <p>
            Hello there, you rock.
        </p>
    </head>
</html>

And here's my b.html file:

<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? Currently, the little part with include a.php isn't working, so I thought I'd ask.

Thanks

2
  • 3
    You should make that a PHP file. Commented Jan 14, 2016 at 1:27
  • <p> is not valid in <head> and <html> is not flow content and therefore invalid in <body> so just include <p>Hello, world<p> not the rest. Commented Jan 14, 2016 at 1:33

2 Answers 2

4

First thing: Change the extension of index.html to index.php. Otherwise the server isn't going to know there's PHP to be parsed.

Second, you don't need to repeat the html, body, head and other document tags that are already in the index.php file. With the includes, you're inserting data into that file, not creating new documents.

<!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:

        <p>
            Hello there, you rock.
        </p>

Revised b.php file:

        <p>
            Hello there, you rock even more.
        </p>
Sign up to request clarification or add additional context in comments.

6 Comments

Are there any drawbacks to me making it a .php file?
For all practical purposes, no. Read more.
if supported and using Apache, they can instruct it to treat .html files as PHP. Plus, they can also (and if supported), use SSI with .shtml and include PHP files. I've done it often.
@Fred-ii-, agreed. But I'm trying to keep in simple, as it doesn't appear the OP must use .html or SSI. Switching to .php is simple, efficient and a good habit to get into, in my view.
@Michael_B FYI: OP reposted stackoverflow.com/q/34781037 it's about brackets.io brackets.io and not adobe-brackets and I closed that question.
|
0

You have three solutions :

  1. change the extension of index.html to index.php

  2. OR you have to include a.php via iframe.

  3. OR you have to call a.php via ajax and then put response where u want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.