Home> php教程> php手册> body text

如何在HTML文件中运行PHP脚本

WBOY
Release: 2016-06-06 19:53:01
Original
1430 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 当访问一个网页时,服务器会根据文件扩展名来判断如何处理页面,一般来说,当检查到扩展名为htm或html时,服务器将文件直接呈现到浏览器端,不做任何处理;如果检测到扩展名是PHP、shtml、ASP或JSP等

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  当访问一个网页时,服务器会根据文件扩展名来判断如何处理页面,一般来说,当检查到扩展名为htm或html时,服务器将文件直接呈现到浏览器端,不做任何处理;如果检测到扩展名是PHP、shtml、ASP或JSP等文件时,服务器会先将这些文件解析成html代码,然后将代码呈现到流程器上。

  这里的问题是:当你遇到一个好的PHP脚本想运用在自己的网站上,而你的网站已经生成静态页面,并且在搜索引擎中有了交好的排名,这种情况下你肯定不愿意将文件改成php扩展名,这时我么要怎么做呢?

  首先,打开htaccess文件,添加下面这一行html代码:

  AddType application/x-httpd-php .html

  或者

  AddType application/x-httpd-php .htm

  如果你只打算在一个页面中包含php脚本,那么你可以这样设置:

  AddType application/x-httpd-php .html

  这样设置后,只有uncletoo.html文件才能执行php脚本。

  注意:

  1、在htaccess文件中添加而不是覆盖内容

  2、任何情况下,程序都是从

'; ?>

如何在HTML文件中运行PHP脚本

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn