This example describes the PHP specified length split string str_split function usage. Share to everyone for your reference, as follows:
Example 1:
$str = ' abcdefgh '; $arr = Str_split ($str, 2);
The results of the operation are as follows:
Array (4) {[0]=> string (2) "AB" [1]=> string (2) "CD" [2]=> string (2) "EF" [3]=> string (2) "GH"}
Example 2:
$str = ' abcdefgh '; $arr = Str_split ($str); $i = 0; $limit = 3; $num = count ($arr), while ($i <= $num-1) { $temp = array (); $for _COUNTBU = ($num-$i) >= $limit? $limit: $num-$i; for ($j = 0; $j < $for _COUNTBU; + + $j) { $temp [] = $arr [$i]; + + $i; } $one = Implode (' ', $temp); $result [] = $one;} Print_r ($result);
The results of the operation are as follows:
Array (4) {[0]=> string (2) "AB" [1]=> string (2) "CD" [2]=> string (2) "EF" [3]=> string (2) "GH"}
I hope this article is helpful to you in PHP programming.