PHP chunk_split() function is used to breaks a PHP string into a number of parts separated by a user-defined term and return modified string. It is an inbuilt function of PHP.
chunk_split($string, $length, $separater);
- $string is a PHP string. It is mandatory.
- $length is the length of every smaller part chunked by this function. It is also mandatory.
- $separater is the user-defined character which used to separate each chunked parts. It is also a mandatory parameter.
<?php $string="Ram's son goes to his school in the morning.\n"; $new_string=chunk_split($string,2,"-"); echo "Old string is : $string <br>"; echo "New String is :$new_string"; ?>