note 69594 added to function.str-replace

From: Date: Tue, 12 Sep 2006 08:26:57 +0000
Subject: note 69594 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-117046@lists.php.net to get a copy of this message
I've come up with a way of using arrays to replace things in a string. Here it is with an example: <?php // Array STR Replace Function By Nesianstyles // Email: crazy.stu@gmail.com function array_str_replace($array, $str) { if (is_array($array)) { foreach ($array as $key => $value) { $str = str_replace($key, $value, $str); } return $str; } } $examplearray = array( '[time]' => '8:00pm', '[date]' => '30th' ); $string = "The time is [time] and date is [date]"; $string = array_str_replace($examplearray, $string); echo $string; // Will echo "The time is 8:00pm and date is 30th" ?> ---- Server IP: 66.163.161.117 Probable Submitter: 219.89.77.62 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/69594 Del: integrated -- https://master.php.net/note/delete/69594/integrated Del: useless -- https://master.php.net/note/delete/69594/useless Del: bad code -- https://master.php.net/note/delete/69594/bad+code Del: spam -- https://master.php.net/note/delete/69594/spam Del: non-english -- https://master.php.net/note/delete/69594/non-english Del: in docs -- https://master.php.net/note/delete/69594/in+docs Del: other reasons-- https://master.php.net/note/delete/69594 Reject -- https://master.php.net/note/reject/69594 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117046) next »