PHP str_split
The PHP str_split function is used to split the string and store it in the PHP array . The feature of str_split is that it can split each character of the entire string at one time, but the disadvantage is that it will cause problems when processing traditional Chinese characters. If you want to deal with it The string function is available in Traditional Chinese. It is recommended to use another PHP split string function mb_split or PHP explode function.
PHP str_split basic syntax
array str_split (the string to be split, the length of each string);
The first parameter "string to be cut" in the grammar should not be explained. What needs to be explained is the latter parameter "length of each string". This second parameter is optional and does not have to be written. , If you write, you can only write integers. What it means is to tell PHP how many characters to split each string into, of course, a space is also considered a character.
PHP str_split example
$string = "Good morning to you.";
$Arr1 = str_split($string); // Cut according to each character
$Arr2 = str_split($string, 3); // According to every three characters Cutting
print_r($Arr1);
print_r($Arr2);
?>

You can see that the output of the first array contains several null values. In fact, it is a space in the original string. It is also considered as a character if it is cut by the PHP str_split function. The second array is Divide into every three characters and cut once, and the space will also be treated as one character. The usage of PHP str_split is relatively simple. If you want to be able to set cutting conditions, or set cutting points, such as cutting strings according to spaces or cutting strings according to commas, you must use the PHP explode function.
Post a Comment
0 Comments