【问题标题】:How to split 4113.52318N in two parts in php [closed]如何在php中将4113.52318N分成两部分[关闭]
【发布时间】:2016-04-29 23:59:37
【问题描述】:

我想将 4113.52318N 分成两部分,例如 41 和 13.52318N 之后我想从第二个值中删除 N。

有什么帮助吗?

【问题讨论】:

  • 我确定您在问这里之前已经尝试过一些东西,让我们看看。
  • your previous question没有太大区别
  • @MarkBaker 实际上是不同的,我想说的是第二部分;)

标签: php string split


【解决方案1】:

有几种方法可以做到这一点,一种是preg_match_all,即:

<?php
$string = "4113.52318N";
$result = preg_match_all('/^(\d{2})([\d.]+)/', $string, $matches);
$partOne = $matches[1][0]; //41
$partTwo = $matches[2][0]; //13.52318

Ideone Demo

【讨论】:

    【解决方案2】:
    Try this :
    $part1 = substr('4113.52318N', 0, 2) // 41
    $part2 = substr('4113.52318N', 3);       // 13.52318N
    $final = substr('4113.52318N', 0, -1);  // 4113.52318
    

    【讨论】:

      【解决方案3】:

      使用子字符串:http://php.net/manual/en/function.substr.php

      $original = "4113.52318N";
      $fortyone = substr($original, 0, 2); // 41
      $other = substr($original, 3);       // 13.52318N
      $n_removed = substr($other, 0, -1);  // 13.52318
      

      【讨论】:

      • 你能告诉我这个“00131.93683E”吗?想拆分成“001”、“31.93683”、“E”。
      猜你喜欢
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-05
      • 1970-01-01
      相关资源
      最近更新 更多