-4

i have string like this:

<?php $string = "52.74837280745686,-51.61665272782557"; ?>

i want access to first string before comma and second string after comma like this:

<?php string1 = "52.74837280745686";  $string2 = "-51.61665272782557" ; ?>

thank you !

Saeed
  • 3
  • 1
  • 3
  • Have you searched into the [PHP documentation](http://php.net/manual/en/ref.strings.php)? One of the tags you attached to the question is also the name of a [PHP function](http://php.net/manual/en/function.explode.php) that can help you. – axiac Jan 29 '16 at 22:01
  • @JayBlanchard apart from the fact that [`split()`](http://php.net/manual/en/function.split.php) is deprecated since PHP 5.3 (and removed in PHP 7), `split(',', $string)` works the same as `explode(',', $string)`. Anyway, my point was about reading the documentation. Simple questions like this one always have the answers in the manual. – axiac Jan 29 '16 at 22:12

1 Answers1

0

This is quite straigtforward

<?php

list($string1, $string2) = explode(",", $string);

or more excant

<?php

$splitTokens = explode(",", $string); // this is what "split" is in other languages, splits an spring by a SEP and retrieving an array
$string1 = $splitTokens[0];
$string2 = $splitTokens[1];
David Steiman
  • 3,055
  • 2
  • 16
  • 22