note 73664 deleted from function.str-replace by bobby

From: Date: Tue, 20 Mar 2007 04:47:03 +0000
Subject: note 73664 deleted from function.str-replace by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124610@lists.php.net to get a copy of this message
Note Submitter: renekoch at hotmail dot com ---- this function enables replace with associative array <?php $str = "hello %name%,\n Your balance is now %balance%"; $data = array( '%name%' => 'Peter', '%balance%' => 100, ); echo( str_kreplace($data, $str) ); #display : # #hello Peter, #Your balance is now 100 # function str_kreplace($replace, $text){ $keys = array(); $values = array(); while ( $data = each($replace) ){ $keys[] = $data['key']; $values[] = $data['value']; } return str_replace($keys, $values, $text); }//function str_kreplace ?>

« previous php.notes (#124610) next »