I am trying to use sprintf on heredoc this way. This will not work. Any idea how to solve this?
$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
Because HEREDOC acts like a double-quoted string, PHP tries to interpolate $sas a variable. Try NOWDOC instead
$s
$i = <<<'EOD' This is your invoice for %1$s %1$s %1$s %1$s EOD;
Or just avoid the dollar signs:
$i = <<<EOD This is your invoice for %1\$s %1\$s %1\$s %1\$s EOD;
This is useful, for example, in PHP 5.2, where there is no nowdoc syntax.