与 html 相比,使用 PHP 有什么缺点吗?

发布于 2024-08-18 22:54:44 字数 192 浏览 4 评论 0原文

我有几页(虽然不是太多),我只是想我可能想将所有页面更改为 php 而不是 html。我计划将来使用 php,只是还没有准备好将其作为我的全职语言。我知道你可以用 html 页面做任何事情,你也可以用 php 页面做,但我只是想知道,在我的网站变得太大而我最终不得不改变之前,与切换到 PHP 相比,是否有任何理由继续使用 html 100 个页面,并重命名数百个链接?

I have a few pages out (not too many though) and I was just thinking that I might want to change all of the pages to php instead of html. I am planning on using php in the future, I am just not quite ready yet to make it my full-time language. I know anythign you can do with html pages, you can do with php pages, but I just wanted to know, is there any reasons to stay with html compared to switching to PHP before my site gets too big and I wind up having to change 100 pages, and renaming hundreds of links?

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

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

发布评论

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

评论(7

当梦初醒 2024-08-25 22:54:44

我能想到的唯一原因是性能略有下降

大多数 Web 服务器(例如 Apache、LightTPD)都配置为将 .html 文件作为静态文件提供服务,而 .php 文件必须首先通过 PHP 引擎进行解释,然后才能进行解释交付给客户。

The only reason I can think of is a small hit in performance.

Most web servers like Apache, LightTPD are configured to serve .html files as static files while .php files will have to first go through the PHP engine to be interpreted and only then delivered to the client.

小鸟爱天空丶 2024-08-25 22:54:44

您的页面仍然是 HTML。 PHP允许动态生成网站,即可以为用户显示用户名。然而,发送到浏览器的仍然是 HTML。

我建议您开始切换到 PHP,因为即使您选择不使用 PHP,您的页面仍然可以正常工作并呈现。但是,如果您坚持使用 .html,然后决定切换到 PHP,那么您将必须转换每个链接。所以现在就转换,节省时间。

我应该注意一件事:通过修改服务器设置,可以将 .html 页面呈现为 PHP,但通常不会这样做。但是,在大多数情况下,会使用 .php,因为大多数服务器已配置为通过 PHP 引擎运行 .php。但如果拥有大型网站的人有这个问题,这是一个选择。

Your pages will still be HTML. PHP allows websites to be generated dynamically, that is, you can display a username for users. However, what is sent to the browser is still HTML.

I recommend that you start switching to PHP because even if you choose not to use PHP, your pages will still work and render fine. However, if you stick with .html and then decide to switch to PHP, then you'll have to convert every single link. So convert now, and save time.

One thing I should note: It is possible, but usually not done, to have .html pages render as PHP by modifying server settings. However, in most cases, the .php is used, as most servers are already configured to run .php though the PHP engine. But in case anyone with a large site has this question, this is an option.

森罗 2024-08-25 22:54:44

你几乎回答了你自己的问题。如果您想要向 HTML 文档添加动态内容,则需要更改文件扩展名,或更改 Web 服务器配置以使 PHP 处理 .html 文件。

一般来说,您会希望每个页面都包含(如果不是动态内容)至少是一致的内容。像页眉和页脚之类的东西,需要在直接 HTML 中进行大量复制粘贴,或者在 php 中使用单个 include() 。 PHP 允许更清晰的组织和更少的重复,即使您不追求页面的动态内容。

You pretty much answered your own question. If you ever reach the stage where you want to add dynamic content to an HTML document, you're going to need to change the file extension, or alter the webserver configuration to have PHP process .html files.

Generally, you will want every page to contain, if not dynamic content, then at least consistent content. Things like headers and footers, that require a massive amount of copy-pasting in straight HTML or a single include() in php. PHP allows for much cleaner organization and much less repetition, even if you're not after dynamic content for your pages.

半仙 2024-08-25 22:54:44

扩展名其实并不重要。在您开始将标记嵌入到文件中以使用脚本处理器之前,PHP 标记不会产生任何实际效果。

The extension doesn't really matter. the PHP marker won't have any real effect until you begin embedding the tags into the files to engage the script processor.

爱殇璃 2024-08-25 22:54:44

虽然使用 PHP 确实可以做任何可以使用 HTML 做的事情,但事实并非如此。使用 PHP,您可以完成 HTML 无法完成的事情。具体来说,您可以使用 PHP 创建动态页面,即内容一旦编写就不再固定的页面。

如果您的页面是静态的,那么您应该继续使用 HTML,如果您需要动态内容,那么您必须使用 PHP(或其他模板/编程语言)。

Although it's true that you can do anything with PHP that you can do with HTML, the contrary is not true. With PHP you can do things that are not possible with HTML. Specifically, you can create dynamic pages with PHP, that is, pages whose contents are not fixed once you've written them.

If your pages are static, then you should continue to use HTML, if you need dynamic content, then you must use PHP (or another template/programming language).

梅倚清风 2024-08-25 22:54:44

当你可以同时拥有 html 时,为什么只使用 html 呢?你可以为静态内容设置静态 html 页面,为动态内容设置 php 页面。您不仅可以使用 php 管理链接,还可以管理几乎所有内容。我正在创建一个只有 30 个页面的网站,我可以说,虽然我有 php 和 html,但有些东西会失控(链接、模板、数据等)。想象一下还有 70 个...

why stay with just html when u can have both? u can have static html pages for static content and php pages for dynamic content. You can manage not just links but almost everything with php. I am creating a site with just 30 pages and I can say, while I do have both php and html, some things get out of hand (links, templates, data, etc). Imagine having 70 more...

毁梦 2024-08-25 22:54:44

好吧,也许没有那么多缺点,除了你可能最终得到这种代码

在此处输入图像描述

Well, there aren't that many disadvantages maybe except for the fact that you might end up with this sort of code

enter image description here

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