【发布时间】:2013-02-04 18:48:44
【问题描述】:
以下代码生成未定义变量 $s 而不是“二号”
define("T1","one");
define("T2","two");
$test="number %2$s";
$test=sprintf($test, T1,T2);
echo $test;
【问题讨论】:
-
用 \$ 转义 $ 或使用单个配额
标签: php
以下代码生成未定义变量 $s 而不是“二号”
define("T1","one");
define("T2","two");
$test="number %2$s";
$test=sprintf($test, T1,T2);
echo $test;
【问题讨论】:
标签: php
单引号解决您的问题。双引号导致 PHP 将您的 '$' 插入为变量。
<?php
define("T1","one");
define("T2","two");
$test='number %2$s';
$test=sprintf($test, T1,T2);
echo $test;
【讨论】: