note 97886 added to function.sprintf

From: Date: Thu, 13 May 2010 19:08:33 +0000
Subject: note 97886 added to function.sprintf
Groups: php.notes 
Request: Send a blank email to php-notes+get-169224@lists.php.net to get a copy of this message
This function still doesn't support replace with named arguments; ie: <?php sprintf( "%(foo)s %(bar)s %(foo)s", array( 'foo' => 'FOO', 'bar' => 'BAR', )); ?> This little php function emulates this feature which is available in other scripting languages: <?php function dictionnaryReplace( $string, $dictionnary ) { $finalDictionnary = array( ); foreach( $dictionnary as $key => $value ) { $finalDictionnary["%($key)s"] = $value; } $string = str_replace( array_keys( $finalDictionnary ), array_values( $finalDictionnary ), $string ); return $string; } ?> Far from perfect. ---- Server IP: 80.64.47.13 Probable Submitter: 87.223.74.210 ---- Manual Page -- http://www.php.net/manual/en/function.sprintf.php Edit -- https://master.php.net/note/edit/97886 Del: integrated -- https://master.php.net/note/delete/97886/integrated Del: useless -- https://master.php.net/note/delete/97886/useless Del: bad code -- https://master.php.net/note/delete/97886/bad+code Del: spam -- https://master.php.net/note/delete/97886/spam Del: non-english -- https://master.php.net/note/delete/97886/non-english Del: in docs -- https://master.php.net/note/delete/97886/in+docs Del: other reasons-- https://master.php.net/note/delete/97886 Reject -- https://master.php.net/note/reject/97886 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169224) next »