开发者

Split string into into array of character pairs [duplicate]

开发者 https://www.devze.com 2023-04-04 18:06 出处:网络
This question already has answers here: Closed 开发者_如何学JAVA11 years ago. Possible Duplicate:
This question already has answers here: Closed 开发者_如何学JAVA11 years ago.

Possible Duplicate:

PHP preg_split string into letter pairs

I have an string looking like this:

$str = "How are you doing?";

How can I turn this string into an array looking like this:

$arr = array("Ho","w ","ar","r ","yo","u ","do","in","g?");


$array = str_split($str, 2);

Documentation.


Use str_split() function.


Take a look at str_split(); it allows you to split a string by a definable amount of characters, so your code would look like:

$arr = str_split($str, 2);

Which will split $str into an array $arr where each element contains two characters,

0

精彩评论

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