iD Tech Camps

Save money on camp with this special offer

Search Our Site

The World's #1 Tech Camp

iD News and Blog

Request a Brochure

A few helpful string and array PHP functions

I’ve been working a great deal with vBulletin, our forums system, and in doing so have had to brush on my PHP. Through the course of preparing the system for the summer I’ve come across a few PHP functions that I was not aware. Here’s a few that you may not know about:

implode: takes an array of strings and concatenates them, using $glue as a separator.

Example: string implode (string $glue, array $pieces)
$before = array(‘one’, ‘two’, ‘three’);
$after = implode(“,”, $before);
echo $after;

Produces:one,two,three

explode: does the exact opposite of implode – it takes a delimiter separated string and transforms it into an array.

Example: array explode (string $delimiter, string $string [, int $limit= -1])
$before = “one,two,three”;
$after = explode(“,”, $before);
var_dump $after;

Produces:
array(‘one’, ‘two’, ‘three’)

var_dump: unlike a typical echo, which will just print “Array” for arrays, var_dump will traverse and print the contents of the array.

Example: void var_dump (mixed $expression [, mixed $expression [, $... ]])
$before = “one,two,three”;
var_dump $before;

Produces:
array(3) {
[0]=>string(1) “one”
[1]=>string(1) “two”
[2]=>string(1) “three”
}

Of course, if you use PHP any more than casually then you already know these functions. But if you frequently jump around among web technologies you might find these useful.

March 26th, 2009 | Tags: , ,

Posted in: iD Tech Bloggers

One Response to A few helpful string and array PHP functions

  1. Is it possible to include a string an an array element?

    Example:
    $key_words[0] = ['password'];
    $key_words[1] = ['required training'];
    $key_words[2] = ['will not be dismissed'];

    So that [1] = required training
    [2] = will not be dismissed

    TIA for any assistance you can provide.

  2. Steve Davis on July 13th, 2009 at 8:38 am

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This entry was posted on Thursday, Mar 26th at 02:32 pm and is filed under iD Tech Bloggers. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Blog Categories

ACCED-I Meeting Exelence On CampusThe World's Best Summer Camps

Blog Archives

CEO's Blog

Tech Bloggers