Re: Parsing Strings

From: Date: Mon, 15 Oct 2007 16:28:10 +0000
Subject: Re: Parsing Strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-263212@lists.php.net to get a copy of this message
On 10/15/07, Philip Thompson <philthathril@gmail.com> wrote: > Hi. > > Before I try and reinvent the wheel, I thought I'd query the list. I want to > take this string: > > thisIsAStringIHave > > and turn it into: > > This Is A String I Have > > Essentially, I want to capitalize the first letter (ucfirst) and then put a > space in front of each uppercase letter. I didn't find a PHP function that > did this (but maybe I didn't look diligently enough). How about this? <?php $string = 'thisIsAStringIHave'; $x = ucwords(preg_replace('/([A-Z])/', ' \\1', $string)); echo $x; ?>

« previous php.general (#263212) next »