PHP: Best way to split string into alphabetic and numeric components

后端 未结 5 1518
情歌与酒
情歌与酒 2021-01-15 15:09

I have several strings of the format

AA11
AAAAAA1111111
AA1111111

Which is the best (most efficient) way to sepa

5条回答
  •  臣服心动
    2021-01-15 15:45

    preg_split should do the job fine.

    preg_split('/(\w+)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE);
    

    The preg library is surprisingly efficient in handling strings, so I would assume it to be more efficient than anything you can write by hand, using more primitive string functions. But do a test and see for your self.

提交回复
热议问题