以下代码生成和未定义变量$ s而不是“number two”
define("T1","one");
define("T2","two");
$test="number %2$s";
$test=sprintf($test, T1,T2);
echo $test;
答案 0 :(得分:7)
单引号解决您的问题。双引号会导致PHP将'$'插入为变量。
<?php
define("T1","one");
define("T2","two");
$test='number %2$s';
$test=sprintf($test, T1,T2);
echo $test;