Home >Backend Development >PHP Tutorial >How to use chunk_split function in php
Usage of chunk_split function in php: [string chunk_split($string, $length, $end)]. The chunk_split function can split a string into a series of smaller parts without changing the original string.
The chunk_split() function is a built-in function in PHP. The syntax is string chunk_split($string, $length, $end), which is used to convert strings into Split into a series of smaller chunks of a specific length; this function does not alter the original string.
(Recommended tutorial: php video tutorial)
How to use the php chunk_split() function?
php The chunk_split() function splits a string into a series of smaller parts; the original string is not changed.
Basic syntax:
string chunk_split($string, $length, $end)
Parameters: This function accepts three parameters, as shown in the syntax above, as described below :
● $string: This parameter specifies the string that needs to be divided into chunks.
● $length: This parameter specifies an integer that specifies the block length, defining the length of the string block; the content is a numeric value, and the default is 76.
● $end: This parameter specifies the line end sequence, defining the content placed at the end of each string block; the content is a string value, and the default is \r\n.
Return value: This function returns a string spllied into smaller chunks.
Let’s take a look at how to use the php chunk_split() function through an example.
Example 1:
<?php $str = "Hello php.cn!"; echo chunk_split($str,3,"..."); ?>
Output:
Hel...lo ...php....cn...!...
Example 1:
<?php $str = "Learning PHP is a good choice!"; echo chunk_split($str,4,"***"); ?>
Output:
Lear***ning*** PHP*** is ***a go***od c***hoic***e!***
The above is the detailed content of How to use chunk_split function in php. For more information, please follow other related articles on the PHP Chinese website!