Course Recommendation:

PHP str_split() Function

Example

<?php
Split the string "Shanghai" into an array:
?>

Run Instance

print_r(str_split("Shanghai"));

Definition and Usage

str_split() function splits a string into an array.

Syntaxstringstr_split(length,
) Description
string Required. Specify the string to be split.
length Optional. Specify the length of each array element. The default is 1.

Technical Details

Return Value:

If length less than 1, the str_split() function will return FALSE.

If length If greater than the length of the string, the entire string will be returned as the only element of the array.

PHP Version: 5+

More Examples

Example 1

Usage length Parameter:

<?php
print_r(str_split("Shanghai",3));
?>

Run Instance