chunk_split() function in php
0 2261
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.
Syntax:
chunk_split($string, $length, $separater);
here,
- $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.
Example:
<?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"; ?>
Output:

Share:
Comments
Waiting for your comments