Computer >> Computer tutorials >  >> Programming >> PHP

chunk_split() function in PHP


The chunk_split() function It is used to split a string into chunks. It returns the split string.

Syntax

chunk_split(str, len, end)

Parameters

  • str − Specifies the string to be split

  • len − Specifies the chunk length

  • end − Specifies the line ending sequence

Return

The chunk_split() function returns the split string.

Example

The following is an example −

<?php
   $s = "Welcome!";
   echo chunk_split($s,1,".");
?>

Output

W.e.l.c.o.m.e.!.

Example

Let us see another example −

<?php
   $s = "My Name is Tom";
   echo chunk_split($s,3,"$$");
?>

Output

My $$Nam$$e i$$s T$$om$$