Parsing Strings
| From: | Philip Thompson | Date: | Mon, 15 Oct 2007 16:16:02 +0000 |
| Subject: | Parsing Strings | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-263211@lists.php.net to get a copy of this message | ||
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). My idea to accomplish
this is to create an array of capital letters. Then iterate through each
letter in the string. If a letter in the string matches a letter in the
array of capital letters, replace that letter with a space + that letter. Is
there a better way than brute-forcing this?? =D
Thanks in advance,
~Philip