Re: preg_replace();

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux