Recently I had a task to split a given string at capitalized characters, having those saved in PHP. I’ve invented the following solution:
<?php
$str = 'TestMyFuncCall';
var_dump(preg_split('/(?=[A-Z])/', $str, null, PREG_SPLIT_NO_EMPTY));
The result is:
array(4) { [0]=> string(4) "Test" [1]=> string(2) "My" [2]=> string(4) "Func" [3]=> string(4) "Call" }
I utilize regular expressions assertions here to avoid character loss.