note 95670 deleted from function.vsprintf by thiago

From: Date: Fri, 15 Jan 2010 12:12:18 +0000
Subject: note 95670 deleted from function.vsprintf by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164997@lists.php.net to get a copy of this message
Note Submitter: rumzucker at gmail dot com ---- I wasn't very content with the functions posted below so here's a small one which covers my needs. <?php /** * vnsprintf * * @param string $format * @param array $args * @return string */ function vnsprintf($format, array $args) { $sArgs = $argKeys = array(); $sFormat = preg_replace('%[\%]([\w]+)[\$]%sie', '"%". array_push(\$argKeys, "$1") ."$"', $format); foreach($argKeys as $arg) $sArgs[] = ( isset($args[$arg]) ? $args[$arg] : null ); return vsprintf($sFormat, $sArgs); } echo vnsprintf('Hello %loc$s! This is a %var$s. [%1$04d]', array( 1 => 42, 'loc' => 'World', 'var' => 'TEST' )); ?>

« previous php.notes (#164997) next »