How to use chunk_split() to split a string into smaller chunks in PHP

4 Answers

0 votes
// string chunk_split( string $body [, int $chunklen = 76 [, string $end = "\r\n" ]])

$str = "PHP Programming";
echo chunk_split($str, 1, ".");

 
/*
run: 

P.H.P. .P.r.o.g.r.a.m.m.i.n.g. 

*/

 



answered Jun 4, 2016 by avibootz
0 votes
// string chunk_split( string $body [, int $chunklen = 76 [, string $end = "\r\n" ]])

$str = "PHP Programming";
echo chunk_split($str, 6, "...");

 
/*
run: 

PHP Pr...ogramm...ing... 

*/

 



answered Jun 4, 2016 by avibootz
0 votes
// string chunk_split( string $body [, int $chunklen = 76 [, string $end = "\r\n" ]])

$s = "abcdefghij";
 
$res = chunk_split($s, 3);
 
echo $res; 

 
/*
run: 

abc def ghi j 

 



answered Jun 4, 2016 by avibootz
0 votes
$s = 'abcdefghij';
 
echo chunk_split(base64_encode($s), 2, ".");
 
/*
run: 

YW.Jj.ZG.Vm.Z2.hp.ag.==. 

*/

 



answered Jun 4, 2016 by avibootz

Related questions

1 answer 135 views
1 answer 154 views
1 answer 125 views
2 answers 336 views
336 views asked Jul 4, 2015 by avibootz
1 answer 214 views
3 answers 328 views
...