PHP中的HTML页面,超级快速建议 [英] PHP in HTML page, Super Quick Advice

查看:99
本文介绍了PHP中的HTML页面,超级快速建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编码方面,我不是天才,但我足够谷歌来解决问题了......我有一个简单的问题。


  1. 我有一个页面index.html,events.html等等,我想添加
    <?php include('exitpopup.php'); ?> ,以便它加载并执行php文件。然而,我不想为了做到这一点而将.html的网页重命名为.php以打破我网站上的所有链接。

有人知道一个解决方法,或者可以建议一个更好的方法来执行此操作吗?
非常感谢!!

解决方案

如果您想要执行php代码.html文件扩展名比您需要做一些htaccess的变化。由于文件扩展名扮演着重要角色,因此它只会告诉浏览器如何处理或解析特定页面。



您可以在根文件夹中创建.htaccess文件您的网站和.htaccess文件添加以下行:

  AddType应用程序/ x-httpd-php .html .htm 

如果您只打算将PHP包含在一个页面中,最好以这种方式进行设置:

 < Files yourwebpage.html> 
AddType应用程序/ x-httpd-php .html
< / Files>

这段代码只会使yourpage.html文件中的PHP可执行文件,而不是所有的



如果您将文件扩展名改为.php比确保工作容易,您可以在html代码之间加入一个php代码。这

 < form method =getaction =latest.php> 
< label><?php echohello?>< / label>
< / form>

see here

详细信息


I'm no genius when it comes to coding, but I google enough to figure things out... I have a quick question.

  1. I have a page "index.html", "events.html" etc... and I want to add <?php include('exitpopup.php'); ?> so that it loads and executes the php file. However, I do not want to have to rename my pages with .html to .php in order to do this... breaking all my links across my website.

Does anyone know a work around or can suggest a better way for me to do this? Many thanks!!

解决方案

If you want to execute php code in .html file extension than u need to do some htaccess changes. Since file-extension plays a major role, it only tells the browser how to handle or parse a particular page.

You can create a .htaccess file at the root folder of your website and in the .htaccess file add this line:

AddType application/x-httpd-php .html .htm

If you only plan on including the PHP on one page, it is better to setup this way:

<Files yourwebpage.html>
AddType application/x-httpd-php .html
</Files>

This code will only make the PHP executable on the yourpage.html file, and not on all of your html pages.

If you are ok with changing your file extension to .php than your work will be quite easy.you can simply include a php code between html code.like this

<form method="get" action="latest.php">
<label><?php echo "hello" ?></label>
</form>

see here

detail

这篇关于PHP中的HTML页面,超级快速建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆