Re: preg_replace();
| From: | Richard Lynch | Date: | Sat, 03 Feb 2007 00:57:17 +0000 |
| Subject: | Re: preg_replace(); | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248215@lists.php.net to get a copy of this message | ||
On Fri, February 2, 2007 12:30 pm, Sébastien WENSKE wrote:
> 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.
You can even go so far so to do both at once:
$text = str_replace(array('|', ' '), array('_', '_'),
$text);
This does ignore the initial requirement of only replacing the ones
between quotes, however...
Something like this will honor the quotes restriction:
$text = preg_replace_all('/(".*)[| ](.*")/", '\\1_\\2', $text);
I probably got the PCRE wrong, but it's close.
Download The Regex Coach and play with it. :-)
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?