PHP chunk_split() function; In this tutorial, 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, "##");
?>
Recommended Posts:
- Autocomplete Search Box in PHP MySQL
- Compare Arrays PHP | PHP array_diff() Function
- Get, Write, Read, Load, JSON File from Url PHP
- Functions: Remove First Character From String PHP
- Remove Specific/Special Characters From String In PHP
- How to Replace First and Last Character From String PHP
- Reverse String in PHP
- Array Push, POP PHP | PHP Array Tutorial
- PHP Search Multidimensional Array By key, value and return key
- json_encode()- Convert Array To JSON | Object To JSON PHP
- PHP remove duplicates from multidimensional array
- PHP Remove Duplicate Elements or Values from Array PHP
- Get Highest Value in Multidimensional Array PHP
- PHP Get Min or Minimum Value in Array
- Convert CSV to JSON PHP – PHP Tutorial
- PHP String to Uppercase, Lowercase & First Letter Uppercase