简体   繁体   English

HTML将我的PHP代码识别为注释

[英]HTML recognizes my PHP code as comments

I want to create a Chrome app, but I have the same problem as this guy. 我想创建一个Chrome应用,但我和这个人有同样的问题 When I add the .php extension and I run the app, it downloads the file.Should I do something more? 当我添加.php扩展名并运行应用程序时,它会下载文件。我应该做更多的事情吗? I have installed PHP (if that means to download and extract the file in the same folder with my app, I'd be wrong). 我已经安装了PHP(如果这意味着下载并使用我的应用程序将文件解压缩到同一文件夹中,我就错了)。 I'm a beginner... :( 我是初学者...... :(

EDIT 编辑

Some of you told me to install Apache or IIS. 有些人告诉我安装Apache或IIS。 I said earlier that I want to create a Chrome app. 我之前说过,我想要创建一个Chrome应用。

Do I need to install Apache? 我需要安装Apache吗? Where would I run it (I don't have a local host, Chrome extensions and apps use the "chrome-extension://" prefix, which means it is hosted on the browser). 我在哪里运行它(我没有本地主机,Chrome扩展程序和应用程序使用“chrome-extension://”前缀,这意味着它托管在浏览器上)。 What about more information (you've all been helpful by now)? 更多信息(你现在都有帮助)?

EDIT 2 编辑2

It turns out that Google Chrome doesn't allow developers toto run PHP inside Chrome apps. 事实证明,谷歌Chrome不允许开发人员在Chrome应用中运行PHP。

Thanks for your help! 谢谢你的帮助!

This means the server is either missing the PHP plugin (either CGI or otherwise) or the the server doesn't recognize that it must pass a file with the extension in to PHP for pre-processing. 这意味着服务器要么缺少PHP插件(CGI或其他),要么服务器无法识别它必须将带有扩展名的文件传递给PHP进行预处理。

If you're on a host out of your control (eg using GoDaddy) then make sure they allow PHP (some of the free hosts won't have PHP as they deam it an unnecessary security risk). 如果你在一个不受你控制的主机上(例如使用GoDaddy),那么确保它们允许PHP(一些免费主机不会使用PHP,因为它们会给它带来不必要的安全风险)。 If it's your own server, make sure you installed PHP and it's enabled. 如果它是您自己的服务器,请确保已安装PHP并且已启用。

If it DOES has PHP installed, but you're not getting it to parse, you'll need to bind the .php extension to the PHP handler using either an .htaccess file or the config. 如果它已经安装了PHP,但你没有得到它解析,你需要使用.htaccess文件或配置将.php扩展名绑定到PHP处理程序。

For apache, your http.conf needs the following (assuming you already have PHP plugin): 对于apache,您的http.conf需要以下内容(假设您已经拥有PHP插件):

AddType application/x-httpd-php .php

Or for something more broad, place an .htaccess file with the above code in your hosted directory. 或者对于更广泛的内容,在托管目录中放置带有上述代码的.htaccess文件。


EDIT 编辑

You mentioned you installed PHP. 你提到你安装了PHP。 I'm going to assume you're using Apache, as IIS now has a Web Extensions installer that would (typically) take care of the "hard part" for you. 我将假设您正在使用Apache,因为IIS现在有一个Web扩展安装程序,它(通常)会为您处理“困难部分”。 So, having said that, open your http.conf (Usually located in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\conf\\ [using 2.2 as a demo version]). 所以,说完了,打开你的http.conf (通常位于C:\\Program Files\\Apache Software Foundation\\Apache2.2\\conf\\ [使用2.2作为演示版])。 Within that file, at the bottom, add the following [replacing files paths to those that correlate to your own install]: 在该文件的底部,添加以下[将文件路径替换为与您自己的安装相关的路径]:

LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"

A better reference can be found by googling "install PHP [version] on [webserver]". 通过谷歌搜索“在[webserver]上安装PHP [版本]”可以找到更好的参考。 Here's just one of the results I was able to locate. 这只是我能够找到的结果之一

Do you have a server installed on your machine? 您的计算机上是否安装了服务器? PHP is a server-side script & unlike Javascript you cannot run it without a server. PHP是一个服务器端脚本,与Javascript不同,如果没有服务器,则无法运行它。

You need an Apache server on your computer. 您的计算机上需要Apache服务器。 download xampp: http://www.apachefriends.org/en/xampp.html and put your files in the htdocs folder. 下载xampp: http//www.apachefriends.org/en/xampp.html并将您的文件放在htdocs文件夹中。


EDIT: This will explain how to install a PHP environment: http://www.tanguay.info/web2008/tutorial.php?idCode=phpDevelopmentQuick 编辑:这将解释如何安装PHP环境: http//www.tanguay.info/web2008/tutorial.php?idCode = phpDevelopmentQuick

PHP files are server side code only. PHP文件只是服务器端代码。 So you need to install a local server like APACHE to get the PHP script to execute. 因此,您需要安装像APACHE这样的本地服务器才能执行PHP脚本。

PHP must be run on a web server, not your desktop. PHP必须在Web服务器上运行,而不是在桌面上运行。 Install PHP on your webserver, then open the PHP file from a web browser via: http://localhost/yourfile.php 在您的网络服务器上安装PHP,然后通过以下网址从Web浏览器打开PHP文件: http://localhost/yourfile.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM