PHP chunk_split() function. Here we would love to share with you, how to split a string with a small part of the chunk using chunk_split() function.
This is a very useful and important function of PHP. You can also use this function according to your requirements.
PHP chunk_split() Function
Definition:- The PHP chunk_split() function, which is used to split or divide a given string into small chunks. And it will return the split string.
Syntax:
chunk_split($str, $length, $end)
Parameters of chunk_split() function
- str − Specifies the string to be split.
- length − Specifies the chunk length.
- end − Specifies the line ending sequence.
Example 1 of chunk_split() function
In this example, we have one string “Welcome to tutsmake.com. Learn PHP chunk function”. We will use the chunk_split() function to split or devide this string:
<?php
// PHP program to demostrate chunk of given string
$str = "Welcome to tutsmake.com. Learn PHP chunk function";
echo chunk_split($str, 2, "*");
?>
The output of the above code is:
We*lc*om*e *to* t*ut*sm*ak*e.*co*m.* L*ea*rn* P*HP* c*hu*nk* f*un*ct*io*n*
Example 2 of chunk_split() function
Let’s take a second example, we will use the chunk_split with “.” to split string with a small part. See the example below:
<?php
// PHP program to demostrate chunk of given string
$str = "DEVELOPER";
echo chunk_split($str, 1, ".");
?>
The output of the above code is:
D.E.V.E.L.O.P.E.R.
Example 3 of chunk_split() function
Let’s take a third example, we will use the chunk_split with “#” to split string with a small part. See the example below:
<?php
// PHP program to demostrate chunk of given string
$str = "DEVELOPER";
echo chunk_split($str, 2, "##");
?>