Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is phtml, and when should I use a .phtml extension rather than .php?

People also ask

What is the difference between HTML and Phtml?

It looks like SHTML = Server Side include HTML (SSI), which is just a fancy way of saying the server can dynamically inject code at the reference point (i.e. where the include is). PHTML is HTML code with inline PHP processing instructions. PHTML is not an encoding method. That link is a PHTML encoder.

What is the correct extension to use when saving PHP files?

php.

What is the use of PHP extension?

php file extension is a plain-text file that contains the source code written in the PHP (it's a recursive acronym meaning PHP: Hypertext Preprocessor) programming language. PHP is often used to develop web applications that are processed by a PHP engine on the web server.

Is it necessary for a file to have PHP extension to run?

If they are used trough include or require , any extension will work.


There is usually no difference, as far as page rendering goes. It's a huge facility developer-side, though, when your web project grows bigger.

I make use of both in this fashion:

  • .PHP Page doesn't contain view-related code
  • .PHTML Page contains little (if any) data logic and the most part of it is presentation-related

.phtml was the standard file extension for PHP 2 programs. .php3 took over for PHP 3. When PHP 4 came out they switched to a straight .php.

The older file extensions are still sometimes used, but aren't so common.


It is a file ext that some folks used for a while to denote that it was PHP generated HTML. As servers like Apache don't care what you use as a file ext as long as it is mapped to something, you could go ahead and call all your PHP files .jimyBobSmith and it would happily run them. PHTML just happened to be a trend that caught on for a while.


To give an example to what Alex said, if you're using Magento, for example, .phtml files are only to be found in the /design area as template files, and contain both HTML and PHP lines. Meanwhile the PHP files are pure code and don't have any lines of HTML in them.


.phtml files tell the webserver that those are html files with dynamic content which is generated by the server... just like .php files in a browser behave. So, in productive usage you should experience no difference from .phtml to .php files.