可能重複:
Include constant in string without concatenating如何使用字符串評估常量?
我怎樣才能得到一個常量字符串中的評估像變量?
$foo = "like";
define('BAR', 'fish');
// None of these give me 'I like to eat fish on Tuesday.'
echo "I $foo to eat BAR on Tuesday.";
echo "I $foo to eat {BAR} on Tuesday.";
echo 'I $foo to eat BAR on Tuesday.';
// This works but is undesirable
echo 'I $foo to eat '.BAR.' on Tuesday.';
不知道這是可能的,但你可以定義一個變量並用它來代替它? – blanknamefornow 2011-02-22 21:30:17
不合需要,但必要。振作起來。 (不同的安德魯!) – Andrew 2011-02-22 22:02:05
這在SO上已經被覆蓋了好幾次,只是措辭有點不同(這就是爲什麼你在詢問時沒有看到它)。 – 2011-02-23 07:28:21