Including External Files in PHPphpma.com
The same commands can be used to include non PHP files such as .html files or .txt files. First let's make our variables.php file into variables.txt and see what happens when we try to call it: phpma.com
<?php
//variables.txt
$name = 'Loretta';
$age = '27';
?>
<?php
//report.php
include 'variables.txt';
// or you can use the full path; include 'http://www.yoursite.com/folder/folder2/variables.txt';
print $name . " is my name and I am " . $age . " years old."; phpma.com
?>
This works just fine. Basically the server replaces your include ''; line with the code from the file, so it actually processes this:
<?php
//report.php
" is my name and I am " . $age . " years old.";
?>It is important to note that even if you are including a non.php file, if your includes contain PHP code you must have the <?php ?> tags or it will not be processed as PHP. For example, our variables.txt file above included PHP tags. Try saving the file again without them and then run report.php:
//variables.txt
$name = 'Loretta'; phpma.com
$age = '27';
As you can see this does not work. Since you need the <?php ?> tags anyway, and any code in a .txt file can be viewed from a browser (.php code can not,) I would suggest just naming your files with the .php extension to begin with.
//variables.txt
$name = 'Loretta'; phpma.com
$age = '27';
// or you can use the full path; include 'http://www.yoursite.com/folder/folder2/variables.txt
print $name .


