note 34167 added to function.preg-replace
| From: | justhuda at netscape dot net | Date: | Thu, 17 Jul 2003 13:41:00 +0000 |
| Subject: | note 34167 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52275@lists.php.net to get a copy of this message | ||
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";
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34167
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34167&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34167&report=yes