This article mainly introduces the usage of the str_split function, which is a php string with a specified length, and analyzes the specific operating skills of the str_split function to separate strings in the form of examples, for more information about how to use the str_split function, see the example in this article. We will share this with you for your reference. The details are as follows:
Example 1:
$str = 'abcdefgh';$arr = str_split($str,2);
The running result is 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 running result is as follows:
array(4) { [0]=> string(2) "ab" [1]=> string(2) "cd" [2]=> string(2) "ef" [3]=> string(2) "gh"}
I hope this article will help you with PHP programming.
For more articles on usage examples of str_split function, which is a string specified by php, refer to the PHP Chinese website!