note 73664 added to function.str-replace

From: Date: Tue, 06 Mar 2007 09:11:13 +0000
Subject: note 73664 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-124138@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 194.145.210.3 Probable Submitter: 217.157.40.26 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/73664 Del: integrated -- https://master.php.net/note/delete/73664/integrated Del: useless -- https://master.php.net/note/delete/73664/useless Del: bad code -- https://master.php.net/note/delete/73664/bad+code Del: spam -- https://master.php.net/note/delete/73664/spam Del: non-english -- https://master.php.net/note/delete/73664/non-english Del: in docs -- https://master.php.net/note/delete/73664/in+docs Del: other reasons-- https://master.php.net/note/delete/73664 Reject -- https://master.php.net/note/reject/73664 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124138) next »