note 23825 deleted from function.preg-replace by dams
| From: | dams@php.net | Date: | Tue, 30 Jul 2002 00:44:18 +0000 |
| Subject: | note 23825 deleted from function.preg-replace by dams | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-33934@lists.php.net to get a copy of this message | ||
Here's a valuable example of Array usage with /e modifier:
error_reporting ( E_ALL | E_NOTICE );
$name = Array(
'first' =>'Maxim'
,'middle' =>'Olegovich'
,'last' =>'Maletsky'
,'email' =>'maxim@php.net'
);
$str = '<a href="mailto:$email">$first
($middle) $last</a>';
$out = preg_replace (
"/(\\$(\w+))/e",
"@\$name['\\2']",
$str
);
echo "
$str
becomes
$out
<br>
";
outputs :
<a href="$email">$first ($middle) $last</a>
becomes
<a href="mailto:maxim@php.net">Maxim
(Olegovich) Maletsky</a>
<br>
NOTE: the 'at' (@) is optional. This is to prevent errors in case of the error reporting
as above. You may as well avoid it if running with different error reporting level.
Another neat idea could be a better regular expression that supports backslashes (\) infront the
sollar sign ($) for the variable. But, that is another story.
-maxim maletsky