PHP: Split string [duplicate]
Solution 1:
explode
does the job:
$parts = explode('.', $string);
You can also directly fetch parts of the result into variables:
list($part1, $part2) = explode('.', $string);
Solution 2:
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
Solution 3:
$string_val = 'a.b';
$parts = explode('.', $string_val);
print_r($parts);
Docs: http://us.php.net/manual/en/function.explode.php