chunk_split – PHP String Functions
Syntax :
string chunk_split(string, chunklength, end) ;
Description :
chunk_split() function will return smaller chunks(pieces) of a string in chunklength parameter.
Parameter :
string – String to be chunked.
chunklength – This is Optional parameter, String will be chunked in chunklength size.Chunk Default size is 76.
end – This is Optional parameter. End will defines what to be placed at the end of each chunk. Default is \r\n
Related articles : str_split(), explode(), wordwrap().
Output :
This will return the chunks of a string after placing “end” parameter values at the end of each chunk.
chunk_split() – PHP Functions Example 1 :
$strExample = chunk_split("Hi All",1,"..");
echo($strExample);
In above example ,We have a string “Hi All”. So, when we apply chunk_split() function. This will add “..” two dots after every chunks of string of length 1(one).
Now Output will become –
H..i.. ..A..l..l..
chunk_split() – PHP Functions Example 2 :
<?php
$strExample = chunk_split("Hi from tutorialmines.net","5","!");
echo($strExample);
?>
In above example ,We have a string “Hi from tutorialmines.net!”. So, when we apply chunk_split() function. This will add “!” (exclamation mark) after every chunks of string of length 5.
Output will be like below:
Hi fr!om tu!toria!lmine!s.net!