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
  • Binary safe case-insensitive string comparison strcasecmp

    strcasecmp

    Binarysafecase-insen
  • Convert string to uppercase strtoupper

    strtoupper

    Convertstringtoupper
  • Remove spaces (or other characters) from the beginning and end of the string trim

    trim

    Removespaces(orother
  • Returns the formatted string sprintf

    sprintf

    Returnstheformatteds
  • Remove HTML and PHP tags from string strip_tags

    strip_tags

    RemoveHTMLandPHPtags
  • Output a string print

    print

    Outputastring
  • Convert the first byte of the string to a value between 0-255 ord

    ord

    Convertthefirstbyteo
  • Calculate the length of the first substring in which all characters in the string exist in the specified character set strspn

    strspn

    Calculatethelengthof
Popular Articles