我正在一个网站上工作,在那里我使用 PHP 来处理一些东西。PHP 已完成,我现在开始设计页面。由于我在本地工作,每次预览页面都必须启动服务器。这有点不方便,因为很多时候当我不在站点上工作并且服务器没有运行时我会得到一些想法。所以我的问题是:
将 PHP 留在里面并只是将文件扩展名更改为 HTML 有什么害处吗?
我只是尝试了它,期望页面上显示 PHP 代码,但令人惊讶的是,所有 PHP 代码都被注释掉了。我记得几年前我在 Windows 上使用 Chrome 时,它并没有像那样工作(现在我在 macOS 上使用 Safari)。
现在 HTML 文件中的 PHP 标签会被自动注释掉,还是浏览器的问题?
无论如何,我将在完成的站点中使用 PHP,这样我就不必每次都启动服务器。
但是我对它的工作原理很感兴趣,因为它将来可能会有用。例如,如果我有一些纯 HTML/CSS/JS 网站,稍后会使用 PHP,那么我可以预先编写 PHP 代码,然后在那里对其进行评论以备后用。
编辑:这是来自 Safari 的屏幕。源代码未注释,但在 Inspector 窗口中。
Since I'm working locally, I have to start up the server every time to preview the page.
This should be a non-issue. You should be using a local development server if you're trying to test things in-context.
Is there's any harm in leaving the PHP inside and just change the file extensions to HTML?
Well, yes, your PHP code is going to be all over the place, potentially having unintended side effects, breaking your page validation, etc.
Do PHP tags in HTML file get automatically commented out nowadays
No. Your PHP code is definitely there, messing up your page in ways you might not see yet until you're busy trying to debug something else and find that your random text in your HTML page (your PHP code) is breaking it.
更新,因为您的屏幕截图:除非您将其注释掉,否则您的页面中实际上没有注释掉。Safari 通过在 DOM 中显示它将您的无效标记视为注释来向您扔骨头。对你很好..不要依赖这个。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句