好的,所以printf/sprint/vprintf都接受某种类型说明符语法%[num] [type].(http://us2.php.net/sprintf参见示例3和4)其中num是该类型的索引.
示例:vprintf('Number%1 $ d string%2 $ s.String%2 $ s,number%1 $ d',array(1,"no"));
是的,它是有限的......你需要维护索引.但它本土的语言和(我认为)快速.
我只想想一下这对于第二阶段是多么有用,如下所示:http://www.techfounder.net/2008/11/18/oo-php-templating/.
(如果有人知道printf/vprintf的速度,将不胜感激)
我正在谈论的完整例子:
frontpage.php:
<html>
<head>
<title> %1$s </title>
</head>
<body>
Hello %2$s! You have reached page: %1$s!
</body>
</html>
whatever.php:
ob_start();
include frontpage.php;
$ob_output = ob_get_clean();
vprintf($ob_output,"Page Title","Bob");