Reputation: 1513
I have a huge text file which I want to explode into an array.
The words in it doesnt have spaces, but each word starts with a capital letter.
How can I explode it to an array taking the capital letters as seperator,without losing the charector?
AppleBallCat should be 1 => Apple 2=> Ball 3=> Cat
Upvotes: 0
Views: 101
Reputation: 798676
$s = 'AppleBallCat';
$a = preg_split('/(?=[A-Z])/', $s);
unset($a[0]);
var_dump($a);
array(3) { [1]=> string(5) "Apple" [2]=> string(4) "Ball" [3]=> string(3) "Cat" }
Upvotes: 3