All TalkersCode Topics

Follow TalkersCode On Social Media

Include PHP File In HTML

Last Updated : Jan 1, 2023

Include PHP File In HTML

In this article we will show you the solution of include PHP file in html, here we need to embed php in html program at first line then define include() within that we can use any external php file.

In php include() method used for takes all the text or code or markup that exists in the specified file and copies it into the file that uses the include.

Which is most useful when we needs to use that particular code on multiple pages in website.

Step By Step Guide On Include PHP File In HTML :-

Here we embedded php code in html page at first line which contain include method with external ‘include.php’ file declaration then we defined html block with table of data.

As we know for creation of table we need to use ‘<table>,<td>,<tr>’ tags so we built table with two columns with two rows.

Which contain ‘Name, Score’ considered as table headers and remaining are data.

<?php include("include.php");?>
<!DOCTYPE html>
<html>
    <head>
        <title>Home Page</title>
    </head>
    <body>
        <table border="1" >
            <tr>
                <th>Name</th>
                <th>Score</th>
            </tr>
            <tr>
                <td>dhanu</td>
                <td>420</td>
            </tr>
            <tr>
                <td>pawi</td>
                <td>480</td>
            </tr>
        </table>
    </body>
</html>
include.php
<?php
echo "This line from external php file";
?>
  1. A php script can be placed anywhere in the document. A php script starts with <?php and end with ?>.
  2. The default file extension for php files is “.php” and php statements end with ‘;’ semicolon.
  3. As we know when we need to use php on html page have to embed php on html page. So we opened php tag at first line which contains include method with external ‘include.php’ file.
  4. Then we starts html code block, here we created table with border width ‘1’ and within that we created two columns, three rows.
  5. The ‘Name, Score’ refers header of table and ‘dhanu,420,pawi,480’ are two users data. Earlier we seen at first we embedded external file ‘include.php’ there we just printed one line of text.
  6. The line of text is ‘This line from external php file’ printed using echo property. As we know echo is a statement which is used to displays output. We can use this with or without parentheses like echo or echo() and it does not return any value then echo is faster than the print statement. Print also same as echo.
  7. We can define anything on both (php,html) of documents above seen just an example if your think to modify them you will do it accordingly.

Conclusion :-

In conclusion now we are able to know how to include php file in html.

When work with php we need to create and process php files at server location and then we need to start the server before execute the program.

When we executing this program on browser we can see both documents contain data as output ‘This is external php file’ which is external php data and below that we can see table with data’s as defined in program with headers ‘Name, Score’.

I hope this article on include PHP file in html helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials