PHP chunk split

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. $string_name1='w3resource.com';  

  2. echo chunk_split($string_name1,1,".");  

  3. echo '
    ';  

  4. echo chunk_split($string_name1,2,"/");  

  5. echo '
    ';  

  6. echo chunk_split($string_name1,1,"--");  

  7. ?>  

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--