doule6314 2015-05-26 06:32
浏览 33
已采纳

从文本到数组的坐标[preg_match]

Maybe someone can help me get coordinates from text to array?

I'm trying use preg_match but no success.

I can remove geometry":{"paths":[[[**" and **]]}}]}) then use some times 'explode' and get coo, but I don't like this idea

Coordinates:

"geometry":{"paths":
[[[485749.91999999998,6108180.6500000004],
[485722.35999999999,6108206],
[485691.14000000001,6108234.3099999996],
[485400.84999999998,6108513.1500000004],
[485368.60999999999,6108545.46],
[485301.53999999998,6108613.1900000004],
[484054.82000000001,6109868.9100000001],
[484051.17566666665,6109872.6840000004]]]}}]});
  • 写回答

2条回答 默认 最新

  • douhui3330 2015-05-26 06:40
    关注

    To figure out my approach in the comment above. Convert the string to valid JSON. Afterwards you can decode the string using json_decode():

    $jsonArr = json_decode('{' . substr($string, 0, -4), true);
    $coordinates= $jsonArr['geometry']['paths'][0]);
    
    var_dump($coordinates):
    

    So you end up with an array of coordinate pairs:

    array(8) {
      [0]=>
      array(2) {
        [0]=>
        float(485749.92)
        [1]=>
        float(6108180.65)
      }
      [1]=>
      array(2) {
        [0]=>
        float(485722.36)
        [1]=>
        int(6108206)
      }
      [2]=>
      array(2) {
        [0]=>
        float(485691.14)
        [1]=>
        float(6108234.31)
      }
      [3]=>
      array(2) {
        [0]=>
        float(485400.85)
        [1]=>
        float(6108513.15)
      }
      [4]=>
      array(2) {
        [0]=>
        float(485368.61)
        [1]=>
        float(6108545.46)
      }
      [5]=>
      array(2) {
        [0]=>
        float(485301.54)
        [1]=>
        float(6108613.19)
      }
      [6]=>
      array(2) {
        [0]=>
        float(484054.82)
        [1]=>
        float(6109868.91)
      }
      [7]=>
      array(2) {
        [0]=>
        float(484051.175667)
        [1]=>
        float(6109872.684)
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?