2012-11-25 96 views
0

不多真正解釋,我只是找不出正確的語法使用變量在包括URL如何將變量插入到PHP'Include'中?

繼承人什麼,我認爲這將是:

$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 

這必須是一個非常簡單的一個分配你在那裏大聲笑,但我只是不能找到我的答案任何地方!

回答

4

使用雙引號(")來分隔字符串。單引號(')字符串中不會出現字符串插值。

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

非常感謝! 所以我必須使用雙引號,只要我想在這樣的東西中使用變量? – ProdigyDoo

+0

@ProdigyDoo或串聯。 – ChocoDeveloper

+0

謝謝:)非常感謝! – ProdigyDoo

0

你也可以使用替代語法如:

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

有時,人們希望有通過IDE爲清楚起見,強調了變量。

+0

個人而言,我沒有看到使用雙引號_和_轉義變量的要點。 – Dale

+0

我通常不會這樣做;但是,這很常見。 –