.php with HTML compared to .html with PHP

When I start building a site that will require both HTML and PHP, should I create a .html file with PHP in it (as in a file, say, index.html, but there will be different tags inside it)? Or should I make .php files and just include HTML in it (like in a file, say index.php, and it will start as PHP, and I just tweak the HTML)?

TL DR: Should I bind HTML to .php files or bind PHP to .html files?

+6
source share
6 answers

It must be a PHP file with an HTML layer. By default, if your server sees an HTML file, it does not consider it necessary to process scripts on the page and display it. If he sees a PHP extension, he knows that he needs to work through a PHP processor.

You can modify htaccess to allow HTML rendering through the processor, but you do not need to create modding, especially if you are a beginner.

+4
source

You are using PHP files with HTML in it

+1
source

You have to "bind" the html to php files. Thus, you know for sure that your code will work on any server, and not just on servers that display html files as php.

0
source

You need to specify in the .htaccess file in order to be able to parse PHP inside the .html file. An easier way is to just do all the .php.

Inevitably, when you are more comfortable working with PHP, you will find out that you will always have some PHP in the file (for example, a requirement or something else), so it’s best to plan this.

0
source

If you are new to PHP, I would recommend creating files with the .php extension since the .php file can be executed by default. Depending on your server configuration, you may need to add some .htaccess directives to allow the PHP file to run in the .html file.

0
source

If you like the .html extensions, you can use .phtml files to template your system, but only for files containing html code. And I prefer to use .php files containing only php code, like classes, etc. (This is what Zend or similar libs do).

0
source

All Articles