【发布时间】:2015-05-09 16:05:28
【问题描述】:
我知道有更多关于这个问题的主题,我已经阅读了它们,但我没有找到答案。
我有一个 index.php,其中包含一堆 .php 包括:header.php、navigation.php、box.php、footer.php,在“pages”div 中,我有一个需要不同(基于来自 navbar.php 或 box.php 的链接)。
navbar.php 示例:
<a href="index.php?v=pag1.php">Page1</a>
<a href="index.php?v=pag2.php">Page2</a>
index.php:
<div id="wrapper">
<div id="header">
<div id="topbox">
<?php include ("box.php"); ?>
</div></div>
<div id="content">
<div id="bara">
<div id="navbar">
<?php include ("navbar.php"); ?>
</div>
</div>
<div id="pages">
<?php include ("$v"); ?>
</div>
</div>
<div id="footer">
<?php include("footer.php"); ?>
</div>
</div>
我在要包含的每个页面上都有一个 $v='pag1.php', $v='pag2.php' 等,但我收到“未定义变量”错误“未定义变量:C 中的 v:\ wamp\www\test\index.php 第 39 行"
如果我在 index.php 中定义变量 $v,它可以工作,但这意味着我必须创建 index.php 的副本,这有点违背了目的。我只希望在 index.php 中包含 pag1.php、pag2.php、pag3.php 等,而不是创建大量副本。我可以为此使用 html :)
我知道我可能会问一个愚蠢的问题,但我是 php 的新手,我不知道在哪里寻找答案。提前谢谢你。
【问题讨论】:
标签: php variables undefined php-include