Today, I was reading Id-PHP mailing list, and I found a question for it’s member. He is asking about to insert a space before a capital letters in a string.
Then, I come up with this solution.
$text = "ThisIsAnExampleOfPHPString";
echo preg_replace('/(\B[A-Z][^A-Z]*)/', ' \1', $text);
And the resut is “This Is An Example Of P H P String” — of course without the double quotes. Simple and neat.
Hi, I am Ganda Manurung. I am a software developer, enterpreneur, and also an ameteur photographer.
2 comments… read them below or add one
Regex Made Confused *kabor*
Regex Made your tasks easier