How to use str split in PHP

In this article I will explain how the str_split() function can be used in PHP.
  • 2066

str_split() function in PHP

  • The str_split() function is used to split a string into an array.
  • The str_split() function will return FALSE, If length is less than 1.
  • In str_split() function, the entire string will be returned as the only element of the array, If length is larger than the length of string.

Syntax

str_split(string,length)

Parameter

  • string string is required parameter. it is specify for shuffle to the string.
  • length length is optional parameter. it is specify for the length of each array element. The default value of length is 1.
Example

The following example show to how the str_split() function can be used in PHP.

<html>

<body>

<h3 style="color: darkgreen;">str_split() function example in PHP</h3>

    <?php

    $string_name='Welcome to C-sharpcorner';

    print_r(str_split($string_name));

    echo '<br>';

    print_r(str_split($string_name,4));

    echo '<br>';

    ?>

</body>

</html>

 

Output

str-split-php.gif
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.