php 和 html 文件扩展名有什么区别?

发布于 2024-11-26 02:37:21 字数 445 浏览 2 评论 0原文

我有一个包含以下代码的 .php 文件。当我将文件的扩展名更改为 .html 时,它的行为方式也相同。任何人都可以解释以下内容:

  1. 为什么文件的行为方式与两个文件的行为方式相同 扩展?
  2. .php.html 文件扩展名有什么区别?

.php 文件

<html>

     <head>
          <!-- some html code -->
     </head>

     <body>
          <?php echo "Hello!" ?>
     </body>

</html>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

何处潇湘 2024-12-03 02:37:21

文件类型只是识别文件的一种方式,您不能总是信任它们。

根据您的网络服务器配置,您将看到不同的结果。

.html 通常仅用于没有服务器端代码的 html。

.php 用于服务器端 php 代码和 html(如果需要)。

它们可以用于任何用途,这仅取决于设置。

The filetype is just a way to identify the file, you can't always trust them.

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

.html is generally use just for html with no serverside code.

.php is used for serverside php code and html if required.

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

清晰传感 2024-12-03 02:37:21

您可以将 Web 服务器配置为以不同方式处理 .php 和 .html 文件。您的网络服务器配置为将两者解释为 PHP。大多数服务器将 .php 作为 PHP 处理,并按原样提供 .html。也就是说,如果您将代码放入 HTML 文件中,PHP 代码将不会运行并会显示在输出中。

有些人发现 URL 中包含 .html 比 .php 更好。如果您的用户下载您的页面并尝试通过双击打开它们,这可能会很有用。

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

Some people find it nicer to have .html in the URL instead of .php. It may be useful if your users download your page and try opening them by double-clicking on them.

旧伤慢歌 2024-12-03 02:37:21

php表示是用PHP语言动态生成的。但是,您看到的并不是最初编写的页面,而是最终的结果。事实上,最终结果是一个 html 文件。

因此,回答你的问题,对于客户端来说,以 php 或 html 结尾的页面将支持完全相同的内容(也就是说,一个 html 文档)。尽管浏览器不应该这样做,但它们经常尝试可视化对它们来说毫无意义的标签(例如,浏览器解释 可能会决定“Hello”是要显示的文本)。

虽然 html 确实不应该有 php 标签,因为它不应该出现在 html 文档中(php 文档被转换为 html 文档,从而删除 php 标签)。

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

同展鸳鸯锦 2024-12-03 02:37:21

扩展名是您的操作系统如何识别您的文件并决定如何处理它,即应该使用哪个应用程序打开它。

php 是一种服务器端脚本语言。它由安装了 php 的 Web 服务器解释。例如,在 XAMPP 中,XAMPP/php 文件夹中的 php.exe 文件解释 php 文件/命令。

HTML 是通过 Internet 发送信息的标准。因此,无论您使用哪种服务器端脚本语言,文件的最终结果都是 html 页面。您使用的Web服务器将处理php命令并将其转换为相应的html并将其发送到您的浏览器。然后浏览器处理(编译)html 代码以显示您的网页。

HTML 本质上就是您在浏览器上看到的所有内容。 PHP 用于与 Web 服务器交互,并处理用户通过表单输入 Web 浏览器的信息,或在链接下执行底层第三方脚本(例如 TCL 脚本),以在后台隐藏自动化功能。在网站上使用或解析 XML 文件或从数据库中提取信息或维护会话信息等等的用户。

一般来说,PHP 处理 Web 应用程序与配置为运行 PHP 的服务器的交互。 HTML 只是将结果转储到浏览器中。

您可以这样想 - HTML 就是您的网站的外观...PHP 使您的网站变得智能,以便它可以与用户交互...

您得到相同的结果,因为 php 可以嵌入到 html 中,并且您的网络服务器处理这两个文件以给出相同的结果。但是,如果您的 Web 服务器上没有安装 php,您将在浏览器中获得输出。

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

php is a server side scripting language. It is interpreted by a web server that has php installed on it . For eg in a XAMPP the php.exe file in XAMPP/php folder interprets the php file/commands.

HTML is the standard for sending information over the internet . So the final result of your file is a html page despite whichever serverside scripting language you use. The web server you are using will process the php commands and convert them to corresponding html and send them to your browser. The browser then processes (compiles) the html code to display you your web page.

HTML is essentially all that you see on your browser. PHP is used to interact with the web server and process information that is entered by the user into a web browser via forms or execute underlying third party scripts (such as TCL scripts) under a link to perform a automation functionality in the background hidden from the user who is using on the web site or parse a XML file or extract information from a database or maintain session information and much more.

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

You can think of it this way- HTML is simply how your web site looks ... PHP is what makes your site intelligent so that it can interact with a user...

your getting the same result because php can be embedded in html and your web server processes both the files to give you identical results. However if you didn't have php installed on your web server you would get as output in your browser.

苍白女子 2024-12-03 02:37:21

区别在于您的 Web 服务器的配置方式,或者您在尝试本地运行文件时是否需要 Web 服务器(即,在您当前使用的计算机上运行文件)。

例如,如果您要在未安装 Web 服务器的计算机上运行这两个版本,则 .html 文件将在浏览器中正常打开,但不会对任何 PHP 标记执行任何操作。然而,.php 文件不一定会运行,浏览器甚至可能会尝试“下载”该文件。

文件扩展名的用途是告诉计算机如何处理给定的扩展名。就像您的计算机将在文字处理器中打开 .doc 文件,或在基本文本编辑器中打开 .txt 文件一样。就像您可以告诉计算机在文字处理器中打开 .txt 文件一样,您可以告诉 Web 服务器以与 相同的方式处理 .html 文件.php 文件(这显然是你的设置要做的)。

The difference lies in how your web server is configured, or whether you need a web server at all when trying to run the files locally (ie - with them on the computer you're currently using).

For example, if you were to run both versions on a computer with no web server installed, the .html file will open in a browser just fine, though without doing anything with any PHP tags. The .php file, however, won't necessarily run and the browser may even try to "download" the file.

What the file extensions are for is to tell a computer what to do with a given extension. Just like your computer will open .doc files in a word processor, or .txt files in a basic 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 handle .html files the same way as .php files (which is what yours is evidently set up to do).

吻安 2024-12-03 02:37:21

php 是一种服务器端脚本语言。每一个带有 php 标签的东西

都会由服务器生成并放入 html 响应中。

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.

灼疼热情 2024-12-03 02:37:21

据我所知,根据扩展名,网络服务器将以一种或另一种方式处理您的文件。另外,例如,您可能有一个不生成任何 HTML 输出的 PHP 文件,但它会重定向到另一个文件。

如果您想提供一个以 *.html 结尾的页面,您可以通过编程来完成。

As far as I Know, depending on the extension the web server will process your file on one way or another. Also, for example, you could have a PHP file that doesn't generate any HTML output, but it redirects to another file.

If you want to give a *.html ended page, you could do it programatically.

不喜欢何必死缠烂打 2024-12-03 02:37:21

您可以将任何扩展名设置为解析为 PHP,因此您的情况的差异仅在于扩展名。如果您在 Apache 配置中禁用将 html 文件解析为 php,则 PHP 将不会解析该文件的内容。这就是全部

例如,您可以在 Apache 配置中添加任何扩展名以供 php 解析,如下所示

application/x-httpd-php myextension

,其中 myextension 是您要解析的文件的扩展名。

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.

可爱暴击 2024-12-03 02:37:21

PHP:Pre Hyper Processot:一种服务器端脚本语言
HTML:超文本标记语言

“.php”和“.html”只是文件扩展名,但是如果您想使用 php 代码,则必须在支持 php 的服务器上运行它。

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.

柠檬色的秋千 2024-12-03 02:37:21

PhP是服务器端。

HTML 是客户端。

另外,在网络上,文件类型没有任何意义。它们被 !DOCTYPE 声明覆盖。

PhP is server side.

HTML is client side.

Plus, on the web, filetypes mean nothing. They are overridden by the !DOCTYPE declaration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文