smarty_modifier_string_format suggestion
| From: | Dominique Peretti | Date: | Mon, 11 Mar 2002 03:07:54 +0000 |
| Subject: | smarty_modifier_string_format suggestion | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-3008@lists.php.net to get a copy of this message | ||
I need to be able to use more than one replacements in string_format
modifier, like this (don't ask me why, but I do !!!):
{html_img file=$IMG_FILENAME[IB][IMG]
name=$smarty.section.IB.index|string_format:"%s_%s":$smarty.section.IMG.inde
x}
Therefore, I suggest this slightly improved version, which allows more
parameters :
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: modifier
* Name: string_format
* Purpose: format strings via sprintf
* -------------------------------------------------------------
*/
function smarty_modifier_string_format($string, $format)
{
if (func_num_args()>2)
{
$param3 = func_get_arg(2);
return sprintf($format, $string, $param3);
} elseif (func_num_args()>3)
{
$param3 = func_get_arg(2);
$param4 = func_get_arg(3);
return sprintf($format, $string, $param3, $param4);
} else
return sprintf($format, $string);
}
?>