我試圖在heredoc上使用sprintf這種方式。它不會工作。任何想法如何解決這個問題?sprintf參數交換和HEREDOC
$i = <<<EOD
This is your invoice for %1$s %1$s %1$s %1$s
EOD;
$year = '2013';
$i = sprintf($i,$year);
echo $i;
Notice: Undefined variable: s in
我試圖在heredoc上使用sprintf這種方式。它不會工作。任何想法如何解決這個問題?sprintf參數交換和HEREDOC
$i = <<<EOD
This is your invoice for %1$s %1$s %1$s %1$s
EOD;
$year = '2013';
$i = sprintf($i,$year);
echo $i;
Notice: Undefined variable: s in
或者只是逃避的美元符號:
$i = <<<EOD
This is your invoice for %1\$s %1\$s %1\$s %1\$s
EOD;
這是非常有用例如在PHP 5.2中沒有nowdoc語法。
你期望的結果是什麼? – srain