How to include php file into html files?

As you already know, with javascript and other lenguages in the web we need to create a special tag to link several files.js into html files. An example of this is as follows:

<scriptsrc="js/myscript.js"></script> // This is in a html file

In php we can do something like this with the reserved word include. We can use it as follow:

<html><head><title>This is a sample</title></head><body><?phpinclude"index.php";

First, I am using a html file and embedded in it there is a php script. In this little code we have only one line of code where we are invoking a php file which content is the following:

        for($x = 0; $x <= 100; $x++){
                if($x%2 == 0){
                        echo "$x\n\t\t";

So, this is a way how we can include php files from others file either in the same carpet or in other.

The advantages of doing this are the following:

  • Our html file is cleaner
  • We can reuse code
  • Is easier and better than copying and pasting code
Escribe tu comentario
+ 2