5

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

$str = 'CreateTechBook' 

Output:

array('Create','Tech', 'Book')
mickmackusa
49k13 gold badges97 silver badges163 bronze badges
asked Sep 15, 2011 at 2:58

2 Answers 2

4
function splitCamelCase($str) {
 return preg_split('/(?<=\\w)(?=[A-Z])/', $str);
}
answered Sep 15, 2011 at 3:01

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);
answered Sep 15, 2011 at 3:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.