preg_split字符串转换成字母对 [英] preg_split string into letter pairs
本文介绍了preg_split字符串转换成字母对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个简单的问题太麻烦了:分割字符串转换成2个字符值的数组,即
I'm having way too much trouble with this simple problem: split a string into an array of 2-character values, i.e.
$string = 'abcdefgh';
// With the correct regex, should return ['ab','cd','ef','gh'];
$array = preg_split("/?????/",$string);
什么是正则表达式混账?
What's the darn regex?
推荐答案
使用 str_split()
来代替。
Use str_split()
instead.
$chunks = str_split($string, 2);
这篇关于preg_split字符串转换成字母对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文