我正在尝试将PHP的include函数与html结合使用,但它无法正常工作。我只是搞乱标签,它似乎很简单,但我无法弄清楚它为什么不起作用......
这是template.php页面:
<!DOCTYPE html>
<html>
<head>
<title>Template</title>
<link href="css/layout.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="wrapper">
<?php
include ("include/header.php");
include ("include/leftcolumn.php");
include ("include/rightcolumn.php");
include ("include/footer.php");
?>
</div>
</body>
</html>
这是我试图包含的header.php页面:
<header>
<p>Header.</p>
</header>
我唯一能想到的是错误的目录,我有一个include文件夹,这是header.php所在的位置,并在include标签中引用...除非我错了,任何提示?感谢
答案 0 :(得分:1)
http://php.net/manual/en/function.include.php 你不需要使用括号试试:
<?php
include "include/header.php";
include "include/leftcolumn.php";
include "include/rightcolumn.php";
include "include/footer.php";
?>
并确保路径正确。
编辑:
php manuel上的每个例子都没有括号。
还有一个问题。你可以尝试执行你的php文件。只是在浏览器中或使用任何wamp服务器应用程序来模拟php的服务器端操作?
答案 1 :(得分:0)
我没有测试过您的代码,但请确保您的路径(在您的include文件夹之前是你的template.php文件到根目录吗?)(说起来很疯狂,但路径是一个常见的问题,它很容易让你发疯)
或者,也尝试这种语法:
包括'include/footer.php';
答案 2 :(得分:0)
删除你的括号()
<!DOCTYPE html>
<html>
<head>
<title>Template</title>
<link href="css/layout.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="wrapper">
<?php
// removing brackets... hopefully it will be working....
include "include/header.php";
include "include/leftcolumn.php";
include "include/rightcolumn.php";
include "include/footer.php";
?>
</div>
</body>
</html>
答案 3 :(得分:0)
删除空间
map