PHP:拆分字符串[复制]

This question already has an answer here:

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

</div>

explode does the job:

$parts = explode('.', $string);

You can also directly fetch parts of the result into variables:

list($part1, $part2) = explode('.', $string);
$array = explode('.',$string);

Returns an array of split elements.

$string_val = 'a.b';

$parts = explode('.', $string_val);

print_r($parts);

Docs: http://us.php.net/manual/en/function.explode.php

The following will return you the "a" letter:

$a = array_shift(explode('.', 'a.b'));

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

to explode with '.' use

explode('\\.','a.b');