This question already has an answer here:
- How can I split a comma delimited string into an array in PHP? 6 answers
How do I split a string by .
delimiter in PHP? For example, if I have the string \"a.b\"
, how do I get \"a\"
?
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\"
?
explode
does the job:
$parts = explode(\'.\', $string);
You can also directly fetch parts of the result into variables:
list($part1, $part2) = explode(\'.\', $string);
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
$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\'));
$array = explode(\'.\',$string);
Returns an array of split elements.
explode(\'.\', \'a.b\');
http://php.net/manual/ru/function.explode.php
to explode with \'.\' use
explode(\'\\\\.\',\'a.b\');