PHP str_split() Function

Definition

The str_split() function splits a string into an array.

Syntax

PHP str_split() Function has the following syntax.

str_split(string,length)

Parameter

ParameterIs Required Description
stringRequired. String to split
lengthOptional. Length of each array element. Default is 1

Return

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

If length is larger than the length of string, the entire string is returned as the only element in the array.

Example 1

Split the string "Hello" into an array:


<?php
print_r(str_split("Hello"));
?>

The code above generates the following result.

Example 2

Using the length parameter:



<?php
print_r(str_split("Hello from java2s.com",3));
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions