This is a discussion on How to insert a space before capital letters in a string? within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am trying to insert a space before all capital letters in a string except the first occurrence. For ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi, I am trying to insert a space before all capital letters in a string
except the first occurrence. For example: FirstSecondThird would become First Second Third Is there a regular expression or short function that can do this? |
|
|||
|
Jeff wrote:
> Hi, I am trying to insert a space before all capital letters in a string > except the first occurrence. For example: > > FirstSecondThird > > would become > > First Second Third > > Is there a regular expression or short function that can do this? Something along the lines of this should help: $string = 'FirstSecondThird'; $string = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $string); print $string; -- Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/ |