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,
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
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
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.
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
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
# [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
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
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,
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
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));
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
12 matches
Mail list logo