Showing posts with label explode(). Show all posts
Showing posts with label explode(). Show all posts

Friday 27 July 2012

PHP explode() and implode()


Using the explode() and implode() Function

<?php
    $str = "Colonia De Sant Jordi.";

    $pieces = explode(" ", $str);

    echo "Nodes: <BR/>\n";
    foreach($pieces as $name) {
        echo trim($name) . "<BR/>\n";
    }
?>

Output:

Nodes:
Colonia
De
Sant
Jordi.

Using explode() with date()

<?php
$ar = explode('|',date("h a|F d, Y"));
echo "It's after $ar[0] on $ar[1]";
?>

Output:

It’s after 03 pm on November 04, 2011

Using implode()

<?php
$arr[0] = "Colonia";
$arr[1] = "De";
$arr[2] = "Sant";
$arr[3] = "Jordi.";
$str = implode(" ", $arr);
print("$str<BR>");
?>

Output:

Colonia De Sant Jordi.