Name
explode()
Synopsis
array explode ( stringseparator
, stringinput
[, intlimit
] )
The explode()
function converts a string into an array using a separator value. For example, the string "head, shoulders, knees, toes" could be converted to an array with the values heads
, shoulders
, knees
, toes
by using the separator ","
. Note that the separator is a comma followed by a space, otherwise the array values would be heads
, shoulders
, knees
, and toes
. For example:
$oz = "Lions and Tigers and Bears"; $oz_array = explode(" and ", $oz); // array contains "Lions", "Tigers", "Bears"
To reverse this function, converting an array into a string by inserting a separator between elements, use the implode()
function.
Get PHP in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.