duanchen7703 2011-06-26 20:25
浏览 44
已采纳

在PHP中将字符串操作分为两部分

Can someone suggest a simple function that will parse a string into two parts, based on everything before and after the comma? I want to split up a latitude longitude pair so that I have two variables instead of one.

I need to turn this:

-79.5310706,43.6918950

into this:

-79.531070 43.6918950

  • 写回答

1条回答 默认 最新

  • dt250827 2011-06-26 20:27
    关注
    $parts = explode(",", "-79.5310706,43.6918950");
    echo $parts[0];
    // -79.5310706
    
    echo $parts[1];
    // 43.69189506
    

    Or if you need it to stay as a space-separated string, just str_replace() the comma to a space!

    echo str_replace(",", " ", "-79.5310706,43.6918950");
    // -79.531070 43.6918950
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?