如何使网站中的html页面包含php
我是第一个承认我在PHP编码方面是新手的人。然而多年前,一位同事给了我一个模式,用于将PHP与HTML结合起来创建网页。现在,我正在寻找改造网站,但我想知道是否有更好的方式来写它?目前,我有一个index.php页面,其布局类似于:如何使网站中的html页面包含php,php,html,Php,Html,我是第一个承认我在PHP编码方面是新手的人。然而多年前,一位同事给了我一个模式,用于将PHP与HTML结合起来创建网页。现在,我正在寻找改造网站,但我想知道是否有更好的方式来写它?目前,我有一个index.php页面,其布局类似于: <?php if (! isset($HTTP_GET_VARS['content']) || ! $HTTP_GET_VARS['content']){ $content="home"; } else $content=$HTTP_GET_VA
<?php
if (! isset($HTTP_GET_VARS['content']) || ! $HTTP_GET_VARS['content']){
$content="home";
}
else
$content=$HTTP_GET_VARS['content'];
//1
if ($content == "home"){
$page_title="Page Title";
$keywords="Keywords found in Meta";
$desc="Description found in Meta";
$style="scripts/style.css";
$popupjs="none";
$storbutnjs="none";
$retreatjs="none";
$rolloverjs="scripts/rolloverjs.js";
$readform_chkjs="none";
$logo="req-files/logo.html";
$sidebar="req-files/sidebar.html";
$main="home.html";
}
//2
if ($content == "about"){
$page_title="Page Title";
$keywords="Keywords found in Meta";
$desc="Description found in Meta";
$style="scripts/style.css";
$popupjs="none";
$storbutnjs="none";
$retreatjs="none";
$rolloverjs="none";
$readform_chkjs="none";
$logo="req-files/logo.html";
$sidebar="req-files/sidebar.html";
$main="about.html";
}
include ("req-files/head.html");
include ($logo);
include ("req-files/navbar.html");
include ($sidebar);
include ($main);
/*include ("scripts/analytics.js");*/
include ("req-files/footer.html");
?>
因此,如果一个人键入http://yourwebsite.com/?content=about
他们将在浏览器中构建完整的About页面,包含所有必需的元、页眉、侧边栏、页脚、javascript、css、分析等。这些必需的部分都是html文件,有些可能有php脚本用于某些$callout,如页面标题、关键字等
我的一个问题是,我的客户机希望将其中一个“($content==”)的名称更改为其他名称。首先,我可以更改变量,但是我必须将旧名称重定向到新名称,这样我们就不会丢失页面排名
例如,http://yourwebsite.com/?content=about
需要重定向到http://yourwebsite.com/?content=about-美国
最终,客户端将重定向所有或大部分页面,使其更直接,http://yourwebsite.com/about-us
。据信,当网站变成WordPress网站时,这将使重建工作更加顺利
那么,有没有更好的方法来写这个?有没有更好的方法重定向URL
谢谢…$HTTP\u GET\u VARS已被弃用。请尝试从官方文档学习PHP 为了回答您的问题,另一个常用系统如下: 文件:include.php
<?php
function topbanner($title) { ?>
<!doctype html>
<html>
<head>
<title><?php echo $title; ?></title>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<header>
Site name, Logo, etc.
<header>
<?php }
function footer() { ?>
<footer>
©2012. Your company name. Best viewed in Mozilla Firefox.
</footer>
</body>
</html>
<?php }
网站名称、标志等。
&抄袭;2012你的公司名称。最好在Mozilla Firefox中查看。
欢迎来到这个网站
内容
这是针对简单页面的。如果需要更复杂的设置,请遵循fork cms的样式,使用.htacess重定向页面。无论哪种方式,页面重命名都意味着它们将失去索引。为什么页面需要经常重命名?
因此,您可以在php(var)中包含html站点
$page=文件获取内容('myHTMLSite.html')代码>
及
stru替换('{header}',$header,$page)代码>您应该看看MVC模式。这是一种更好、更稳健的方法。谢谢大家的帮助。是的,我一直在努力学习PHP,但我有点迷路了。我想我也需要一本新书。。。感谢您的支持。
<?php require_once('include.php'); topbanner("Title of this page"); ?>
<h3>Welcome to this site</h3>
<p>Content content content</p>
<img src="image.jpg" />
<?php footer(); ?>