What is the difference between php and html file extensions?

I have a .php file with the following code. Although I change the file extension as .html , then it also behaves the same way. Can anyone explain the following:

  • Why does the file behave the same with both extensions?
  • What is the difference between .php and .html file extensions?

.php file

 <html> <head> <!-- some html code --> </head> <body> <?php echo "Hello!" ?> </body> </html> 
+7
source share
10 answers

A file type is just a way to identify a file; you cannot always trust them.

Depending on the configuration of your web server, you will see different results.

.html is usually used only for html without serveride code.

.php is used for server-side PHP code and html if required.

They can be used for anything, it just depends on the configuration.

+8
source

You can configure the web server to handle .php and .html files in different ways. Your web server is configured to interpret as PHP. Most servers handle .php as PHP and serve as .html as-is. That is, if you put your code in an HTML file, the PHP code will not run and will be displayed in the output.

Some people find it better to use .html in the URL rather than in .php format. This can be useful if your users are loading your page and trying to open them by double-clicking on them.

+2
source

php indicates that it is dynamically generated using the PHP language. However, you do not see the page because it was originally written, but rather the end result. The end result is essentially an html file.

To answer your question, to the client, a page ending in php or html will support exactly the same content (i.e. an html document). Despite the fact that browsers should not, they often try to render tags that do not make sense to them (browser interpretation of <? Php echo "Hello!"?> For example, may decide that "Hello" is the text to display).

Although html really should never have php tags in it, since it is not intended for an HTML document (php documents are translated into html documents, thereby removing php tags).

+1
source

The difference is how your web server is configured or whether you need a web server when trying to run files locally (i.e. with them on the computer that you are currently using).

For example, if you run both versions on a computer without a web server installed, the .html file opens in a browser just fine, although it does nothing with any PHP tags. However, the .php file does not necessarily start, and the browser may even try to “download” the file.

To expand the files, you must tell the computer what to do with this extension. Just as your computer will open .doc files in a word processor or .txt in a main text editor. And just like you can tell your computer to open .txt files in your word processor, you can tell the web server to process .html files just like .php files (this is what your explicitly installed).

+1
source

an extension is how your operating system recognizes your file and decides what to do with it, for example, which application should be opened.

php is a server side scripting language. It is interpreted by the web server on which php is installed. For example, for example, in XAMPP, the php.exe file in the XAMPP / php folder interprets the php file / command.

HTML is the standard for sending information over the Internet. Thus, the end result of your file is an html page, despite any server-side scripting language you use. The web server you are using will process the php commands and convert them to the corresponding html and send them to your browser. Then the browser processes (compiles) the html code to display your web page.

HTML is all that you see in your browser. PHP is used to interact with the web server and process information that the user enters in the web browser through forms or executes basic third-party scripts (for example, TCL scripts) using the link to perform automation functions in the background, hidden from the user who uses A website either parses an XML file or extracts information from a database or maintains session information and much more.

In general, PHP handles the interaction of a web application with a server configured to run PHP. HTML just dumps the results in the browser.

You can think of it this way: HTML is just what your website looks like ... PHP is what makes your website intelligent so that it can interact with the user ...

you get the same result because php can be embedded in html and your web server processes both files to give you the same results. However, if you did not have php installed on your web server, you will receive it in your browser.

+1
source

php is a server side scripting language. All that has a php tag

will be generated by the server and placed in the html response.

0
source

As far as I know, depending on the extension, the web server will process your file anyway. In addition, for example, you may have a PHP file that does not generate HTML output, but redirects it to another file.

If you want to provide a * .html complete page, you can do this programmatically.

0
source

you can install any extension that will be parsed as PHP, so the difference in your case will only be in the extension. If you disable html files in your Apache configuration, which will be processed as php, and the contents of the file will not be parsed by PHP. It's all

For example, you can add any extension in your Apache configuration that will be processed by php, for example

 application/x-httpd-php myextension 

where myextension is the file extension you want to parse.

0
source

PHP: Pre Hyper Processot: server-side script HTML language: Hypertext Markup Language

". php" and ".html" are just file extensions, however, if you want to use PHP code, you must run it from a server that supports php.

0
source

PhP is the server side.

HTML is the client side.

In addition, on the Internet, file types mean nothing. They are redefined by declaration! DOCTYPE

0
source

All Articles