Re: preg_replace() help

From: Date: Sat, 14 Jul 2007 04:58:09 +0000
Subject: Re: preg_replace() help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-258843@lists.php.net to get a copy of this message
On Fri, July 13, 2007 3:52 pm, Rick Pasotto wrote: > I have quotes like the following: > > $txt = 'A promise is a debt. -- Irish Proverb'; > > I'd like to replace all the spaces afer the '--' with   > > This is what I've tried: > > $pat = '/( --.*)(\s|\n)/U'; You might want to use \\s and \\n, so you are 100% clear that the PHP strings have a single \ in them, and that they don't have a newline. The .* is probably messing you up... You could probably manage this with some kind of preg_replace_callback, but it seems to me it would be easier to do: $txt = 'A promise is a debt. -- Irish Proverb'; $pos = strpos($txt, '--'); $html = substr($txt, 0, $pos) . '--' . str_replace(' ', ' ', substr($txt, $pos + 2)); -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#258843) next »