Re: preg_replace(); [solved]

From: Date: Fri, 02 Feb 2007 20:21:36 +0000
Subject: Re: preg_replace(); [solved]
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-248208@lists.php.net to get a copy of this message
nice ! thanks Steffen & Ed ! i've just add '[src|background] *= *' to make sure that the replacement takes effect only in THML tag's attributes if (preg_match_all("![src|background] *= *\"(.+)\"!sU", $htmlContent, $match)) { for ($i=0; $i<count($match[0]); $i++) { $old = $match[1][$i]; $new = preg_replace("!\|| !", "_", $old); $htmlContent = str_replace("\"$old\"", "\"$new\"", $htmlContent); } } ----- Original Message ----- From: "Steffen Ebermann" <eseh@nognu.de> To: <php-general@lists.php.net> Cc: "Sébastien WENSKE" <canardwc@canardwc.com> Sent: Friday, February 02, 2007 9:01 PM Subject: Re: [PHP] preg_replace();
This always works for me: if (preg_match_all("!\"(.+)\"!sU", $var, $match)) { for ($i=0; $i<count($match[0]); $i++) { $old = $match[1][$i]; $new = preg_replace("!\|| !", "_", $old); $var = str_replace("\"$old\"", "\"$new\"", $var); } } On Fri, Feb 02, 2007 at 07:30:37PM +0100, Sébastien WENSKE wrote:
Hi all, I want replace the "|" (pipe) and the " " (space) chars where are between " (double-quotes) by an underscore "_" with the preg_replace(); funtction. Can someone help me to find the correct regex. Thanks in advance Seb


« previous php.general (#248208) next »