PHP Explode

The PHP explode function can break apart variables into several smaller pieces. You can specify the splitting parameter, and the result will be returned in an array which can be echoed or use for other purposes within your script. If I have a variable called “$string” that contains a very long string, I can use PHP explode to break it apart into smaller pieces. In this example, I have a variable that contains both the directory and filename. I will use PHP explode to break them apart.


$string = "thisisalongstring/breakmeapart.php";
$shorten = explode("/", $string);

The Result:

echo $shorten[0];    // thisisalongstring
echo $shorten[1];    // breakmeapart.php

PHP explode is a fun little function.