PHP explode

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

PHP : explode() function

Description

The explode() function is used to split a string.

Version

(PHP 4 and above)

Syntax

explode(delimiter, string_name, limit) 

Parameters

Name

Description

Required /
Optional

Type

delimiter

Sets the boundary string within the input string.

Required

String

string_name

The string to be split.

Required

String

limit

Refers to the maximum number of elements in the output array if set to +ve value. If set to -ve value, all but the last element will be present in the output array.

Optional

Integer

Return values

An array of strings.

Value Type : Array.

Pictorial Presentation

php-string-explode()

Example :

  1. $class_list='V,VI,VII,VIII,IX,X';  

  2. $classes=explode(",",$class_list);  

  3. print_r($classes);  

  4. ?>  

Output :

Array ( [0] => V [1] => VI [2] => VII [3] => VIII [4] => IX [5] => X )