note 95670 added to function.vsprintf

From: Date: Fri, 15 Jan 2010 01:38:09 +0000
Subject: note 95670 added to function.vsprintf
Groups: php.notes 
Request: Send a blank email to php-notes+get-164985@lists.php.net to get a copy of this message
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' )); ?> ---- Server IP: 192.35.244.50 Probable Submitter: 212.183.119.19 ---- Manual Page -- http://www.php.net/manual/en/function.vsprintf.php Edit -- https://master.php.net/note/edit/95670 Del: integrated -- https://master.php.net/note/delete/95670/integrated Del: useless -- https://master.php.net/note/delete/95670/useless Del: bad code -- https://master.php.net/note/delete/95670/bad+code Del: spam -- https://master.php.net/note/delete/95670/spam Del: non-english -- https://master.php.net/note/delete/95670/non-english Del: in docs -- https://master.php.net/note/delete/95670/in+docs Del: other reasons-- https://master.php.net/note/delete/95670 Reject -- https://master.php.net/note/reject/95670 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164985) next »