I am having a .php
file with the following code. While I am changing the extension of the file as .html
then also it is behaving in the same way. Can anyone explain the following:
- Why the file is behaving in the same manner with both the extensions?
- What is the difference between the
.php
and.html
file extensions?
.php
file
<html>
<head>
<!-- some html code -->
</head>
<body>
<?php echo "Hello!" ?>
</body>
</html>
you can set any extension to be parsed as PHP, so difference in your case is only in extension. If you disable html files in your Apache configuration to be parsed as php than content of file won't be parsed by PHP. That is all
For example you can add any extension in your Apache configuration to be parsed by php, like this
where myextension is extension of the file you want to parse.
A php indicates that it is dynamically generated using PHP language. However, you don't see the page as it was originally written, but rather the end result. The end result is, in fact, an html file.
So to answer your question, to the client, a page ending in php or html will support exactly the same contents (which is to say, an html document). Even though browsers shouldn't, they often attempt to visualize tags which make no sense to them (browser interpreting <?php echo "Hello!" ?> for instance might decide "Hello" is the text to display).
Though an html really should never have php tags in it because it isn't meant to be in an html document (php documents are traslated into html documents, thus removing php tags).
PHP: Pre Hyper Processot : a server side script language HTML: Hyper text markup language
".php" and ".html" are just the file extensions however if you want to use php code you must run it off a server which supports php.
php is a server side scripting language. Every thing that have a tag php
will be generated by the server and put in the html response.