如何在浏览器中显示/运行 PHP 文件?好像它是一个网页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43402842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:49:21  来源:igfitidea点击:

How do I show / run a PHP file in a browser? As if it was a webpage

phphtmlbrowser

提问by SeekLoad

How do I run a PHP file in my browser? I know what the file is for and I know how it looks because I tested it online. But now I downloaded it locally to my computer and I do not know how to run it on my browser. Is there a way maybe to link it to a HTML like you do with JavaScript or CSS to make it work on a web browser also after it is online how will I manage it to work?

如何在浏览器中运行 PHP 文件?我知道该文件的用途,并且我知道它的外观,因为我在网上对其进行了测试。但是现在我将它本地下载到我的计算机上,我不知道如何在我的浏览器上运行它。有没有办法像使用 JavaScript 或 CSS 那样将它链接到 HTML 以使其在网络浏览器上也能正常工作,我将如何管理它才能正常工作?

If I can not link then maybe I can use iframe to see it in a HTML iframe. Is that possible? Yet the question is not based about iframe, but I do not exclude the iframe possibility too. That is why I ask of it too.

如果我无法链接,那么也许我可以使用 iframe 在 HTML iframe 中查看它。那可能吗?然而,这个问题不是基于 iframe,但我也不排除 iframe 的可能性。这也是我问它的原因。

Or even better, if there is a way to both link and use iframe for the PHP?

或者甚至更好,如果有一种方法可以同时链接和使用 PHP 的 iframe?

The entire PHP file I got is a email function that works and looks a loot like a HTML and JavaScript file, but it is written in PHP. If I simply change the name to the file from PHP to HTML I can open it in the browser and it looks like a HTML file with few defects since it is a PHP file after all.

我得到的整个 PHP 文件是一个电子邮件功能,它的工作原理看起来像一个 HTML 和 JavaScript 文件,但它是用 PHP 编写的。如果我只是将文件的名称从 PHP 更改为 HTML,我可以在浏览器中打开它,它看起来像一个几乎没有缺陷的 HTML 文件,因为它毕竟是一个 PHP 文件。

The file I downloaded was from here: https://www.hscripts.com/scripts/php/registrationMailer.php

我下载的文件来自这里:https: //www.hscripts.com/scripts/php/registrationMailer.php

And it is this PHP file I am specifically intrested in: https://www.hscripts.com/scripts/php/HMAD/hmailer.php

这是我特别感兴趣的这个 PHP 文件:https://www.hscripts.com/scripts/php/HMAD/hmailer.php

NOTE:I am not asking of "PHP code is not being executed, instead code shows on the page" as the other page is asking. I am asking of "How do I show / run a PHP file in a browser? As if it was a webpage."

注意:我不是在询问“PHP 代码没有被执行,而是代码显示在页面上”,因为另一个页面正在询问。 我在问“如何在浏览器中显示/运行 PHP 文件?就好像它是一个网页一样。”

回答by TurtleTread

You do not need a web serverto execute PHP script unless you need to run it using a browser. Install PHP in your operating system and include PHP path in your environment path or variable (depending on what OS) you are using. If you are just using the script for the mailing stuff from your own computer, you don't need a web server like apache, you just need PHP and its cli program installed and you be run php scripts directly. Google the web how on how run PHP command line. Or visit this official documentation link: http://php.net/manual/en/features.commandline.php

不需要 Web 服务器来执行 PHP 脚本,除非您需要使用浏览器运行它。在您的操作系统中安装 PHP,并在您使用的环境路径或变量(取决于什么操作系统)中包含 PHP 路径。如果您只是在自己的计算机上使用脚本来发送邮件,则不需要像 apache 这样的 Web 服务器,只需要安装 PHP 及其 cli 程序,然后直接运行 php 脚本即可。谷歌网络如何运行 PHP 命令行。或者访问这个官方文档链接:http: //php.net/manual/en/features.commandline.php

回答by Yaakov Ainspan

You need to download a server, and install it. If you want to go to the trouble, you can get XAMPP, and once it's installed, move the PHP file to the root of your installation (usually c:\xampp\htdocs\on windows) and then use the url localhost/script.phpin your browser.

您需要下载服务器并安装它。如果你想解决问题,你可以得到XAMPP,一旦安装,将 PHP 文件移动到安装的根目录(通常c:\xampp\htdocs\在 Windows 上),然后localhost/script.php在浏览器中使用 url 。