w3resource
PHP Tutorial

PHP: chunk_split() function

Description

The chunk_split() function is used to split a string into a series of smaller chunks.

Version:

(PHP 4 and above)

Syntax:

chunk_split(string_name, string_length, end_string) 

Parameters:

Name Description Required /
Optional
Type
string_name The string to be split. Required String
string_length The chunk length. Optional Integer
end_string The line ending sequence. Optional String

Return values

The extracted string.

Value Type: String.

Pictorial Presentation

php-string-chunk_split()

Example:

<?php
$string_name1='w3resource.com';
echo chunk_split($string_name1,1,".");
echo '<br>';
echo chunk_split($string_name1,2,"/");
echo '<br>';
echo chunk_split($string_name1,1,"--");
?>

Output:

w.3.r.e.s.o.u.r.c.e...c.o.m.
w3/re/so/ur/ce/.c/om/
w--3--r--e--s--o--u--r--c--e--.--c--o--m--

View the example in the browser

See also

PHP Function Reference



New Content: Composer: Dependency manager for PHP, R Programming