note 31766 added to function.preg-replace
| From: | bdwebtech at yahoo dot ca | Date: | Fri, 02 May 2003 21:27:32 +0000 |
| Subject: | note 31766 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47403@lists.php.net to get a copy of this message | ||
It seems that when using the /e modifier it prevents you from using double quotes (") inside of
the $replacement string, even if you escape it with a back slash (\").
For example, putting a (") or (\") around the (gram) in the $replacement string will
result in a parse error.
This would be useful when outputting HTML attributes and values.
Code Example:
<?php
$subject = "I love PHP and JS.";
$pattern = '/(PHP|JS)/e';
$replacement = " strtoupper( \"programming $1\" ); ";
print preg_replace($pattern, $replacement, $subject);
// Output: I love PROGRAMMING PHP and PROGRAMMING JS.
?>
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+31766
http://master.php.net/manage/user-notes.php?action=delete+31766
http://master.php.net/manage/user-notes.php?action=reject+31766