Current Location: Home> Function Categories> chunk_split

chunk_split

Split the string into smaller chunks
Name:chunk_split
Category:String
Programming Language:php
One-line Description:Split the string into a series of smaller parts.

Definition and usage

The chunk_split() function divides the string into a series of smaller parts.

Note: This function does not change the original string.

Example

Example 1

Split the string once after each character and add "." after each segment:

 <?php
$str = "Shanghai" ;
echo chunk_split ( $str , 1 , "." ) ;
?>

Try it yourself

Example 2

Split the string once after every six characters and add "..." after each segment:

 <?php
$str = "Hello world!" ;
echo chunk_split ( $str , 6 , "..." ) ;
?>

Try it yourself

grammar

 chunk_split ( string , length , end )
parameter describe
string Required. Specifies the string to be divided.
length Optional. numeric value, defining the length of the string block. The default is 76.
end Optional. String value, which defines what is placed at the end of each string block. The default is \r\n.
Similar Functions
Popular Articles