Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources

The PHP str_split() function is used to split the given string into an array. This function has an optional parameter which is used to specify the number of characters for each split with default value 1. Please note that it does not change the original string.


str_split(string, length)


string Required. Specify the string to split
length Optional. Specify length of each element of the array. Default is 1.

Return Value

Returns the array containing split string as elements of the array.


In the below example, str_split() function to used to split string MyString and return an array containing split string as elements of the string.

  $MyString = "Hello World!";
  $NewString = str_split($MyString,3);


The output of the above code will be:

    [0] => Hel
    [1] => lo 
    [2] => Wor
    [3] => ld!

❮ PHP String functions