开发者

PHP String Split Problem

I'm having trouble figuring out how to split a string into groups of like characters. I have a few strings of rather random character groups similar to this one:

aaabb2222eee77777

I would like to be able to split them like so:

aaa, bb, 2222, eee, 77777

and then be a开发者_JAVA技巧ble to count the number of characters in each set. What would be the easiest way to do this? I'm really not sure where to start. Thank you!


You can then iterate through the array and get the strlen() of each item:

preg_match_all('/(.)\1*/', 'aaabb2222eee77777', $matches);
$matches = $matches[0];
Array
(
   [0] => aaa
   [1] => bb
   [2] => 2222
   [3] => eee
   [4] => 77777
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜