note 21382 deleted from function.preg-replace by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 12:31:02 +0000 |
| Subject: | note 21382 deleted from function.preg-replace by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57474@lists.php.net to get a copy of this message | ||
Note Submitter: cluebie
----
Printing arrays has been tried a few times above but I haven't been able to use the solutions
provided.
Here is what worked for me:
------
$description["useless"] = "moocow";
$description["boring"] = "fubar";
$description["hard"] = "easy now!";
$text = "Arrays in preg are [desc:hard] ";
print preg_replace("/\[desc:([
\w]+)\]/e","\$description['\\1']",$text);
------
This will print "Arrays in preg are easy now! "
The preg finds [desc:hard] and uses "hard" as the index into the array called
$description. Note the /e in the pattern, the function is enclosed in double quotes, and
$description is escaped with \.