PHP chunk_split() Function

PHP chunk_split() function is used to splits a string into smaller parts or chunks. The function does not alter the original string.

Syntax:


chunk_split(string,length,end)  
 
Parameter Description Required/Optional
string String to split Required
Length Specify the length of the chunks. Default is 76 Optional
end Specify what to place at the end of each chunk Optional

Example 1


 <?php 
 $str = "Hello shorat innovations!";  
 echo "Your string is: ".$str;  
 echo "By using 'chunk_split()' function your string is: ".chunk_split($str,6,"...");   
 ?>
                            

Output

Hello ...shorat... innov...ations...!...

Example 2


<?php 
$char =052; 
$str ="Hello";  
echo "Your string is: ".$str. "<br>" 
echo "By using 'chunk_split()' function your string is: ".chunk_split($str,1,".");   
?>
        

Output

Your string is: Hello By using 'chunk_split()' function your string is: H.e.l.l.o.