douyunhuan9886 2017-09-25 14:21
浏览 47
已采纳

如何从PHP中删除Indian Mobile Numbers中的国家/地区代码?

I'm receiving mobile numbers with country code (in 12 digits) from a API response. But I need the mobile number without the country code (in 10 digits).

What I'm receiving:

919999999999  

What I need:

9999999999  

What I have tried:

$mobile = "919999999999";
$split = preg_split("/[\]+/", $mobile);
$newmobile = $split[2].$split[3].$split[4].$split[5].$split[6].$split[7].$split[8].$split[9].$split[10].$split[11].$split[12];  

I know this is wrong. Please help!

  • 写回答

4条回答 默认 最新

  • doupa8922 2017-09-25 14:29
    关注

    Here's a version that will check that the mobile length is 12 and the first 2 characters contain the country code, before trying to remove them. This can be useful in case the input of the number can vary a bit:

    $mobile = "919999999999";
    if (strlen($mobile) == 12 && substr($mobile, 0, 2) == "91")
        $mobile = substr($mobile, 2, 10);
    echo $mobile;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误