将PHP文件包含到HTML文件中 [英] Include PHP file into HTML file
问题描述
我正在研究一个可能需要在所有html页面上更改相同内容的项目。所以我想我会创建一个php文件,只需要改变它,这样它就可以在网页上的所有页面上进行更改。
这些文件保存为:
index.html
number.php
示例:
------------------------ (HTML FILE)----------------------------
< HTML>
< head>
< title>主页< / title>
< / head>
< body>
< h1>电话号码< / h1>
<?php include('number.php')?>
< / body>
< / html>
--------------------- ---(PHP FILE)----------------------------
<?php
echo 4895553268;
?>
我可以在不改变文件扩展名的情况下做什么所有我的html到php。我发现的作品,但我只想改变HTML页面中的代码。我已经尝试过包含require标签,但是这并不起作用,所以我尝试了脚本标签,并且似乎无法使其正常工作。
在目录中创建一个.htaccess文件,并将此代码添加到.htaccess文件中。
pre $
AddHandler x-httpd-php。 html .htm
或
AddType application / x-httpd-php .html .htm
它会强制Apache服务器将HTML或HTM文件解析为PHP脚本
I'm working on a project that may have to change the same content on all html pages. So I figured I would create a php file and only have to change that so it changes on all pages over the web.
The files are saved as:
index.html
number.php
EXAMPLE:
------------------------(HTML FILE)----------------------------
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Phone Number</h1>
<?php include('number.php') ?>
</body>
</html>
------------------------(PHP FILE)----------------------------
<?php
echo 4895553268;
?>
What could I do without changing the file extension of all my html's into php. I've found that works but I would like to only change the code in the html page. I've tried include require tags and that didn't work so I tried script tags and can't seem to make it work right.
Create a .htaccess file in directory and add this code to .htaccess file
AddHandler x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
It will force Apache server to parse HTML or HTM files as PHP Script
这篇关于将PHP文件包含到HTML文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!