PHP chunk_split: How to Split String in PHP


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:

  1. Autocomplete Search Box in PHP MySQL
  2. Compare Arrays PHP | PHP array_diff() Function
  3. Get, Write, Read, Load, JSON File from Url PHP
  4. Functions: Remove First Character From String PHP
  5. Remove Specific/Special Characters From String In PHP
  6. How to Replace First and Last Character From String PHP
  7. Reverse String in PHP
  8. Array Push, POP PHP | PHP Array Tutorial
  9. PHP Search Multidimensional Array By key, value and return key
  10. json_encode()- Convert Array To JSON | Object To JSON PHP
  11. PHP remove duplicates from multidimensional array
  12. PHP Remove Duplicate Elements or Values from Array PHP
  13. Get Highest Value in Multidimensional Array PHP
  14. PHP Get Min or Minimum Value in Array
  15. Convert CSV to JSON PHP – PHP Tutorial
  16. PHP String to Uppercase, Lowercase & First Letter Uppercase
Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?