str_split() Function
It returns an array containing parts of the string.
Syntax
str_split(string, length);
Parameters
- string: It specifies the string to be checked, it can also be a variable name of type string.
- length: It specifies the length of each part of the string to be stored in the string, by default, it is 1. If the length is larger than the size of the string, then the complete string is returned.
Example: This example illustrates the basic implementation of the str_split() Function in PHP.
PHP
<?php $str = "w3wiki" ; print_r( str_split ( $str )); echo "<br>" ; print_r( str_split ( $str , 3)); ?> |
Output:
Array (
[0] => G
[1] => e
[2] => e
[3] => k
[4] => s
[5] => F
[6] => o
[7] => r
[8] => G
[9] => e
[10] => e
[11] => k
[12] => s
)
Array (
[0] => Gee
[1] => ksF
[2] => orG
[3] => eek
[4] => s
)
Explain some string functions of PHP
In the programming world, a string is considered a data type, which in general is a sequence of multiple characters that can contain whitespaces, numbers, characters, and special symbols. For example, “Hello World!”, “ID-34#90” etc. PHP also allows single quotes(‘ ‘) for defining a string. Every programming language provides some in-built functions for the manipulation of strings. Some of the basic string functions provided by PHP are as follows: