hotti: Alternative zu sprintf gesucht

Beitrag lesen

hi,

Was mir noch nicht so gefällt, ist das Mitschleifen der Prozentzeichen in den Keys (Stash-array). Kriegn wir das noch mit einer Zeile Code hin??

Ok, ich habs:

  
# Extended Replace  
class XR{  
	public function xr($haystack = '', $stash = array()){  
		$needles = array_map(create_function('$e','return("%$e");'), array_keys($stash));  
		$s = str_replace($needles, $stash, $haystack);  
		return $s;  
	}  
}  
  
$xr = new XR;  
print $xr->xr("Me and %you and a dog named %boo are %friends\n",  
	array('you' => 'Otto', 'boo' => 'Axel', 'friends' => 'dicke Freunde'));  
# Me and Otto and a dog named Axel are dicke Freunde  

Danke Lobo