What is the difference between php and html file e

2019-02-09 06:46发布

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:

  1. Why the file is behaving in the same manner with both the extensions?
  2. 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>

10条回答
再贱就再见
2楼-- · 2019-02-09 07:21

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

application/x-httpd-php myextension

where myextension is extension of the file you want to parse.

查看更多
神经病院院长
3楼-- · 2019-02-09 07:23

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).

查看更多
Fickle 薄情
4楼-- · 2019-02-09 07:30

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.

查看更多
聊天终结者
5楼-- · 2019-02-09 07:31

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.

查看更多
登录 后发表回答