PHP sprintf()没有替换参数交换

时间:2013-02-04 18:48:45

标签: php

以下代码生成和未定义变量$ s而不是“number two”

define("T1","one");
define("T2","two");

$test="number %2$s";

$test=sprintf($test, T1,T2);

echo $test;

1 个答案:

答案 0 :(得分:7)

单引号解决您的问题。双引号会导致PHP将'$'插入为变量。

<?php
define("T1","one");
define("T2","two");

$test='number %2$s';

$test=sprintf($test, T1,T2);

echo $test;

See it working