In php, you can use the str_split() function to split a string into an array, which splits the string into several substrings of the desired length and combines them into an array; syntax "str_split(string,length)".

In php, you can use the str_split() function to split strings into arrays. This function splits a string into an array by a specified length.

The str_split() function splits the string into several substrings of the desired length and combines these substrings into an array.

Syntax format:

1

str_split(string,length)

  • string Required. Specifies the string to be split.

  • length Optional. Specify the length of each array element. The default is 1.

1

2

3

4

5

<?php

$str="Hello";

$arr=str_split($str);

var_dump($arr);

?>

 

1

2

3

4

5

<?php

$str="Hello";

$arr=str_split($str,2);

var_dump($arr);

?>

 

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

1

2

3

4

5

<?php

$str="Hello";

$arr=str_split($str,-1);

var_dump($arr);

?>

 

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

1

2

3

4

5

<?php

$str="Hello";

$arr=str_split($str,5);

var_dump($arr);

?>

 

 

Related articles

php crop image steps

php crop image steps: 1, create a PHP sample file; 2, use "function imageCropper(){...}" method to achieve the image does not change the cropping; 3, through the "function imageZoom (){...}" method to achieve proportional cropping of the image.

How to replace alt with php regular?

php regular to achieve the replacement alt method: 1, create a PHP sample file; 2, get the content to be replaced; 3, through "<img.*?src=[\"|\'](. *?) [\"|\']. *? >" can be replaced by the regular implementation.

How to convert svg to svg in php?

php svg to jpg method: 1, create a PHP sample file; 2, by "public function svgtojpg(){$image =...}" method to achieve the conversion.

Two basic output methods for php

The two basic output methods of php are "echo" and "print". echo is used to output one or more strings, which can take multiple arguments and have no return value, with the syntax "echo($ str)"; and print is used to output a string that can only take one

How to display a mess of php images?

php image display a mess of solutions: 1, open the corresponding PHP code file; 2, in the page header plus "header ("Content-Type: image/jpg");" code to declare the image type can be.

php can't load js css

php can not load js css solution: 1, check the correct path to load; 2, prohibit the use of absolute path; 3, use relative path to load the file can be.

php how to check user ip

php query user ip method: 1, get user ip by "$_SERVER["REMOTE_ADDR"]" way; 2, get user ip by "($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];" to get the user ip and so on.

How to invert a string by word in php

Inversion methods: 1. use "explode(' ',$str)" statement to convert string to array; 2. use "array_reverse($arr)" statement to invert the array and return the array in the reverse order of elements; 3. use "implode(' ',$arr)" statement to convert the inver

php get maximum value in several numbers

In php, you can use the max() function to get the maximum value among several numbers. The function works by calculating and returning the maximum value among several specified values, with the syntax "max(value1,value2,...) ;".

How to convert php image to base64

php image to base64 method: 1, get an image address; 2, through the "chunk_split(base64_encode($gambar));" method to convert the image to base64 string format can be.