LaVOZs

The World’s Largest Online Community for Developers

'; Include 'count.html.php' - LavOzs.Com

This book 'php and mysql novice to ninja' said that to include the files count.html and count.php, I must type the following into the bottom of the count.php file:

include 'count.html.php';

However, this does not seem to work unless it is just count.html without the .php.

Is this book accurate or not? I cannot find anything online about this way of including.

I've seen two separate lines of including tags such as:

include 'a.html';
include 'b.php';

Sorry for the shit formatting. I've never posted to this site before.

count.php:

<?php
$output = '';
for ($count = 1; $count <= 10; $count++) {
        $output .= $count . ' ';                 
}

include 'count.html.php';
?>

count.html:

<!DOCTYPE html>
<html lang="eng">
    <head>
        <meta charset="utf-8">
        <title>counting to ten</title>          
    </head>
    <body>
        <p>
            <?php echo $output; ?>

        </p>
    </body>
</html>

include looks for a file name exactly matching what you put in the quotes, it will not include two different files at once as you are describing.

Your count.html file contains PHP code in it, so it shouldn't have the .html extension, it would most commonly use .php or since it looks mostly like an html template file, you could use .phtml. The extensions .php and .phtml do the exact same thing, but generally by convention if you have a file exclusively with php code, you would name it .php, and it it has a lot of html, you might want to name it .phtml. Either is fine, but not the plain .html.

Assuming you decided to name it count.phtml, then your two files would then look like:

count.php

<?php
$output = '';
for ($count = 1; $count <= 10; $count++) {
        $output .= $count . ' ';                 
}

include 'count.phtml';
?>

count.phtml

<!DOCTYPE html>
<html lang="eng">
    <head>
        <meta charset="utf-8">
        <title>counting to ten</title>          
    </head>
    <body>
        <p>
            <?php echo $output; ?>
        </p>
    </body>
</html>

The author was showing his personnel method, which is confusing. Basically using the .php at the end of .html.php as a reminder to himself that it was related to the .php document. It made the html code appear as php, and the author was not the clearest.

Related
What is the difference between #include <filename> and #include “filename”?
What is the difference between include and extend in Ruby?
What is the difference between include and require in Ruby?
What is the difference between #import and #include in Objective-C?
How to include() all PHP files from a directory?
How do I include a JavaScript file in another JavaScript file?
Difference between require, include, require_once and include_once?
Include another HTML file in a HTML file
What is the correct syntax of ng-include?
Cannot display HTML string