在 Node.js 模块库中有很多好用的模块。接下来我们为大家介绍几种常用模块的使用: 序号 模块名 & 描述 1 OS…
October 23, 2017
PHP: 通过字母大小写分割字符,大写字符分割到数组, php explode at capital letters?
I have strings like,
$a = 'helloMister'; $b = 'doggyWaltz'; $c = 'bumWipe'; $d = 'pinkNips';
How can I explode at the capital letters, search on google for some time and came back with nothing!
Thanks.
解决:
If you want to split helloMister
into hello
and Mister
you can use preg_split
to split the string at a point just before the uppercase letter by using positive lookahead assertion:
$pieces = preg_split('/(?=[A-Z])/',$str); // helloMister => hello,Mister
and if you want to split it as hello
and ister
you can do:
$pieces = preg_split('/[A-Z]/',$str); // helloMister => hello,ister
参考:https://stackoverflow.com/a/8998418
本文:PHP: 通过字母大小写分割字符,大写字符分割到数组, php explode at capital letters?