dongzhankou2090 2013-10-31 04:43
浏览 54
已采纳

sprintf参数交换和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
  • 写回答

2条回答 默认 最新

  • dp0518 2013-10-31 04:45
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?