PHP’s inclusion functions are very useful for keeping your script neat and tidy. Using the PHP include() function, we can include remote files on one page. In fact, this very page is using includes to include the tutorial text!

Let’s say we have a file called myname.txt. As you can see, this is a text file, so it contains raw text. Below is the text contained in myname.txt.

Mike

Above shows the text in myname.txt. As you can see, it simply says “Mike“. Now, the below code is a PHP script.

<?php
echo("Hello, my name is");
include("myname.txt");
// The following would be echoed: 'Hello, my name is Mike'.
?>

The above code uses the echo() function to echo the text “Hello, my name is“. We then use the include() function to include the file called “myname.txt“, which includes the text “Mike“. Since they are echoed right after one another, it outputs “Hello, my name is Mike“. Simple! You can use PHP includes to include PHP code as well.