2013-09-24 32 views

回答

5
$result = preg_split('/^(\s*)/', ' test ', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); 

输出

array(2) { 
    [0]=> 
    string(2) " " 
    [1]=> 
    string(5) "test " 
} 
0

这里有一个更简单的办法:

$result = preg_split('/\b/', ' sth', 2); 

输出:

array (size=2) 
    0 => string ' ' (length=3) 
    1 => string 'sth' (length=3)