note 34167 deleted from function.preg-replace by tularis

From: Date: Sun, 18 Jun 2006 13:14:31 +0000
Subject: note 34167 deleted from function.preg-replace by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114324@lists.php.net to get a copy of this message
Note Submitter: justhuda at netscape dot net ---- REPLACE + ARRAYS Sometimes you have string ini database field like this "1, 3, 6"; you have definition for the numbers in an array, and you want to replace them and print. This is the solution I found : $string = "1, 3, 6"; $days=array(1 => "Monday","Sunday","Tuesday", "Wednesday","Thursday","Friday","Saturday"); print preg_replace("/([1-6])/e","\$days['\\1']",$string); result : "Monday, Tuesday, Friday";

« previous php.notes (#114324) next »