note 31766 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:01:04 +0000
Subject: note 31766 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55682@lists.php.net to get a copy of this message
Note Submitter: bdwebtech@yahoo.ca ---- 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. ?>

« previous php.notes (#55682) next »