要在PHP字符串中調用函數,可以使用雙引號或者heredoc或nowdoc語法。例如:
$name = "John";
echo "Hello, $name!"; // 輸出:Hello, John!
// 調用函數
echo "Today is " . date('Y-m-d');
$name = "Alice";
$str = <<<EOD
Hello, $name!
Today is {date('Y-m-d')}
EOD;
echo $str;
$name = "Bob";
$str = <<<'EOD'
Hello, $name!
Today is {date('Y-m-d')}
EOD;
echo $str;
無論使用哪種方法,都可以在字符串中調用函數并輸出結果。