The original file I created was helloworld.html. The modified version not only has different code, it also has a different extension, see below:
helloworld.php
- Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>HTML to HTML-PHP Conversion: File 1</title>
</head>
<body>
<!-- Include file starts here -->
<?php include("helloworld.inc") ;?>
<!-- Include file ends here -->
</body>
</html>
The include file looks like this:
helloworld.inc
- Code: Select all
<!-- Include insert starts here -->
<p>Hello World!</p>
<!-- Include insert ends here -->
When the modified
helloworld.php is executed, the php extension tells the computer that it needs to look for php code and replace it with whatever it is told to replace it with. In this case, it is told to replace the code with the include file called
helloworld.inc. Once the replacement has been made, it should become just another simple HTML file again and then it is executed.
The extension of the include file is arbitrary. In this case I wanted it made obvious that the file was only to be used when included within another file. The extension could just as easily been php. Also, the name of the include file is totally arbitrary. I felt that it made a lot of sense to have the same name and a different extension so they would show in a directory list together so I wouldn't have to search for either file.
The only other requirements are that the computer this is to run on should be capable of running php programs and, as I said earlier, the main program, in this case helloworld.php, needs to be called from an html program. The second requirement is not necessary if the file is a standard index.html file.
As you know, if a folder not containing an index.html file is accessed on the Internet, it will display a list of files. If the index.html file is there and executable, it will be run, thereby hiding the file list. An index.php file will work the same way.
My only problem with the above is that my local computer is not capable of running php code, so I would have to make changes, upload it to my host, and then test to verify that everything was working as required. Since I like to make modifications on my local machine and test them before uploading them to my host, this will require a change in the way I maintain my website but I think it will be well worth it.
Comments are welcome and any mistakes in presentation are all mine.