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:
<script src="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>
                <?php
                        include "index.php";
                ?>
        </body>
</html>
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:
<?php
        for($x = 0; $x <= 100; $x++){
                if($x%2 == 0){
                        echo "$x\n\t\t";
                        $x++;
                }else{
                        $x++;
                }
        }
?>
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
Curso de PHP con Composer
COMPARTE ESTE ARTÍCULO Y MUESTRA LO QUE APRENDISTE
0 Comentarios
para escribir tu comentario




