Split a string with a period

How would I split this string:

string: 'item.35'

So it comes out like this:

$type = 'item';
$id = '35';

I know there are a lot of string fucntions but I have no idea what would be easiest.
Maybe implode(), an array would be fine

explode();
or
split();
or one of the other string functions.

Implode does the opposite :wink:

Okay cool, thanks.
I was looking up strsplit() and forgot implode/explode, yeah its explode lol.

I did this:


$a = explode('.', $id);
echo $a[0];
echo $a[1];

That will work!

There are a multitude of different ways to achieve such a simple task. Here’s a few (you already know about the first one):


// 1. EXPLODE! *pop*
list($type, $id) = explode('.', 'item.35', 2);

// 2. Scan a formatted string
list($type, $id) = sscanf('item.35', '%[a-z].%d');