如何将变量插入PHP“Include”?

时间:2012-11-25 06:49:24

标签: php url variables syntax include

真的没什么可解释的,我只是想弄清楚在包含URL中使用变量的正确语法

继承人的想法:

$round_num=1;
include '../../fixtures/round{$round_num}fix.php';

它返回通常的:

Warning: include(../../fixtures/round{$round_num}fix.php) [function.include]: failed to open stream: No such file or directory

对于那些分配给你的人来说这一定是非常简单的大声笑,但我无法在任何地方找到答案!

2 个答案:

答案 0 :(得分:4)

使用双引号(")来分隔字符串。单引号(')字符串中不会出现字符串插值。

$round_num=1;
include "../../fixtures/round{$round_num}fix.php";

答案 1 :(得分:0)

您还可以使用其他语法,例如:

include "../../fixtures/round" . $round_num . "fix.php";

为了清晰起见,有时人们更喜欢用IDE突出显示变量。

相关问题