Ulyssesonline

the tech surfer

  • Home
  • About
  • Archives
You are here: Home / General / PHP Explode

September 22, 2011

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.

Example:

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

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

The Result:

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

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

PHP explode is a fun little function.

Filed Under: General, PHP Tagged With: explode, PHP

Trackbacks

  1. Links 24/9/2011: Linux 3.1 RC7, Plasma Active OS | Techrights says:
    September 24, 2011 at 9:50 am

    […] PHP Explode […]

Copyright © 2003 - 2018