如何在逗号之前拆分字符串?

时间:2016-01-29 21:57:24

标签: php string split

我有这样的字符串:

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

我希望在逗号之前访问第一个字符串,在逗号之后访问第二个字符串,如下所示:

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

1 个答案:

答案 0 :(得分:0)

这是非常困难的

<?php

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

或更多的兴奋

<?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];