5

I want split a string of capitalized words into an array of individual words.

$str = 'CreateTechBook' 

Output:

array('Create','Tech', 'Book')

2 Answers 2

4
function splitCamelCase($str) {
    return preg_split('/(?<=\\w)(?=[A-Z])/', $str);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Great solution. Btw (?<=\\w) imho can be improved to (?<!^)
@zerkms Yep, that will be nice~
0
 preg_replace('/([a-z0-9])?([A-Z])/','$1 $2 $3',$string);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.