Re: [PHP] Separating words based on capital letter

2007-04-25 Thread Robin Vickery
On 25/04/07, Dotan Cohen [EMAIL PROTECTED] wrote: On 25/04/07, Richard Lynch [EMAIL PROTECTED] wrote: On Tue, April 24, 2007 4:16 pm, Dotan Cohen wrote: I have some categories named in the database as such: OpenSource HomeNetwork I'd like to add a space before each capital letter,

Re: [PHP] Separating words based on capital letter

2007-04-25 Thread Dotan Cohen
On 25/04/07, Robin Vickery [EMAIL PROTECTED] wrote: $string = preg_replace('/(?=\w)([[:upper:]])/', ' $1', $string); turns this is OpenSourceCode to this is Open Source Code Another great solution, Robin, thanks. I've learned a LOT from this thread. Dotan Cohen

Re: [PHP] Separating words based on capital letter

2007-04-25 Thread Al
Note: several of the folks used / as the delimiter. Actually, it can be almost anything that will not be in the $string. Generally, I use % simply because it's easier to spot when I forget the delimiters. Also, note Robin's use of the metachar [[:upper:]]. metacharacters can very useful. My

[PHP] Separating words based on capital letter

2007-04-24 Thread Dotan Cohen
I have some categories named in the database as such: OpenSource HomeNetwork I'd like to add a space before each capital letter, ideally not including the first but I can always trim later if need be. As I'm array_walking the database, I have each value at the moment I need it in a string $item.

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Tijnema !
On 4/24/07, Dotan Cohen [EMAIL PROTECTED] wrote: I have some categories named in the database as such: OpenSource HomeNetwork I'd like to add a space before each capital letter, ideally not including the first but I can always trim later if need be. As I'm array_walking the database, I have

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Richard Davey
Dotan Cohen wrote: I have some categories named in the database as such: OpenSource HomeNetwork I'd like to add a space before each capital letter, ideally not including the first but I can always trim later if need be. As I'm array_walking the database, I have each value at the moment I need

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-04-25 00:16:40 +0300: I have some categories named in the database as such: OpenSource HomeNetwork I'd like to add a space before each capital letter, ideally not including the first but I can always trim later if need be. As I'm array_walking the database, I

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Arpad Ray
Roman Neuhauser wrote: implode(' ', preg_split('~(?=[[:upper:]])~', 'FooBarBaz', -1, PREG_SPLIT_NO_EMPTY)); Or just.. preg_replace('/\B[A-Z]/', ' $0', 'FooBarBaz') Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Dotan Cohen
Thanks, all for the suggestions. Richard, that code is a masterpeice. I have no problems with regexs, though, only with the regex that I wasn't doing properly. Roman, I'm still picking your code apart and trying to understand everything. I see I'll be learning quite a bit from that. Arpad,

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Richard Lynch
On Tue, April 24, 2007 4:16 pm, Dotan Cohen wrote: I have some categories named in the database as such: OpenSource HomeNetwork I'd like to add a space before each capital letter, ideally not including the first but I can always trim later if need be. As I'm array_walking the database, I

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Myron Turner
Richard Lynch wrote: Why rule out PCRE, which is probably the best weapon for the job? $string = ltrim(preg_replace('([A-Z])', ' \\1', $string)); Don't mean to be pedantic, but you left out the '/. . ./': $string = $string = ltrim(preg_replace('/([A-D])/', \\1, $string));

Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Dotan Cohen
On 25/04/07, Richard Lynch [EMAIL PROTECTED] wrote: On Tue, April 24, 2007 4:16 pm, Dotan Cohen wrote: I have some categories named in the database as such: OpenSource HomeNetwork I'd like to add a space before each capital letter, ideally not including the first but I can always trim