I'm looking for the quickest approach to splitting a string into its leading spaces and the rest of it?
····sth
should become array("····", "sth")
and ·sth·
- array("·", "sth·")
* ·
= space
$result = preg_split('/^(\s*)/', ' test ', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
outputs
array(2) {
[0]=>
string(2) " "
[1]=>
string(5) "test "
}
Here's a more simple approach:
$result = preg_split('/\b/', ' sth', 2);
Would output:
array (size=2)
0 => string ' ' (length=3)
1 => string 'sth' (length=3)