Alex Rivera | Logout

PHP: Split string

Asked 2011-03-01T19:03:46.310
79

How do I split a string by . delimiter in PHP? For example, if I have the string "a.b", how do I get "a"?

Edit
Report

2 Answers

28

explode('.', $string)

If you know your string has a fixed number of components you could use something like

list($a, $b) = explode('.', 'object.attribute');
echo $a;
echo $b;

Prints:

object
attribute
answered 2011-03-01T19:10:34.277
-1

To explode with '.', use:

explode('\\.', 'a.b');
answered 2011-03-04T16:06:07.577

Your Answer