【问题标题】:How To Split String Before After Comma? [duplicate]如何在逗号之前拆分字符串? [复制]
【发布时间】:2016-01-29 21:57:23
【问题描述】:

我有这样的字符串:

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

我想访问逗号之前的第一个字符串和逗号之后的第二个字符串,如下所示:

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

谢谢!

【问题讨论】:

  • 你搜索过PHP documentation吗?您附加到问题的标签之一也是可以帮助您的PHP function 的名称。
  • @JayBlanchard 除了split() 自 PHP 5.3 起已弃用(并在 PHP 7 中删除),split(',', $string)explode(',', $string) 的工作方式相同。无论如何,我的意思是阅读文档。像这样的简单问题总是在手册中有答案。

标签: php string split


【解决方案1】:

这个很简单

<?php

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

或更多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];

【讨论】:

    猜你喜欢
    • 2015-08-15
    • 2013-02-03
    • 2014-02-11
    • 2011-07-13
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 2012-05-24
    相关资源
    最近更新 更多