Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sprintf argument swapping and HEREDOC

I'm trying to use sprintf on a heredoc this way. It wont 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

like image 598
jmenezes Avatar asked Oct 31 '13 04:10

jmenezes


1 Answers

Because HEREDOC acts like a double-quoted string, PHP is attempting to interpolate the $s as a variable. Try NOWDOC instead

$i = <<<'EOD'
This is your invoice for %1$s %1$s %1$s %1$s
EOD;
like image 132
Phil Avatar answered Oct 04 '22 18:10

Phil