Explode or split string and display array

Posted under » PHP on 31 January 2011

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.

Basic example

$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

Limit parameter example

$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str, 2));

Take note that split() is depreciated in PHP7.

For Python, read this.

web security linux ubuntu Raspberry   git   javascript css python django drupal php apache mysql  MongoDB AWS data  ML AI