Re: Re: SeparatingWords

From: Date: Sat, 24 Aug 2002 14:08:19 +0000
Subject: Re: Re: SeparatingWords
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-113933@lists.php.net to get a copy of this message
Hessu, =What did you require? =See second solution below. =Regards, =dn > Yes, it would and yes you can, but I'll leave that up to you :) =so it may or may not have been a 'solution'! > > Philip, > > What about "SoftwareVersion Thingy"? > > Won't that end up as "Software Version Thingy" - with two spaces before the > > "T"? > > Can the RegEx be 'turned off' if the u/case letter is already preceded by a > > space? > > (sorry, may not be Hessu's requirement = my curiosity) > > Regards, > > =dn > > > > > This works. > > > $word = "SoftwareVersionThingy"; > > > $word = ereg_replace("([A-Z])", " \\1", $word); > > > $word = ltrim($word); > > > -philip > > > > > > On Thu, 22 Aug 2002, Hessu wrote: > > > > Hi, > > > > I have strings like FileName, SoftwareVersion etc. > > > > How can I add space between words? Somehow with preg_replace perhaps? > > > > First letter of each word is capitalized. > > > > -Hessu- =suggested PCRE regex solution: $RegExIn = "SoftwareVersion Thingy Validity"; $RegExPattern = "|\B[A-Z].{2}|"; echo "Using character string: $RegExIn~"; echo "<br>RegEx ~$RegExPattern~"; echo "<br>Replaced:" . preg_replace( $RegExPattern, " $0", $RegExIn ) . "~"; *****

« previous php.general (#113933) next »