dsaob80228 2014-06-23 05:52
浏览 105
已采纳

使用PHP中的国家/地区代码格式化电话号码

I am working on website that the customer submit his phone number and need to be able to convert the customer's phone number from 0553322111 to 966553322111 so I can use it to compare with the records in a MySQL database.

How would I go about this with PHP?


When the user submit his phone number in the HTML Page

He will submitted as 0553322111.

PHP

<?php
// store the submitted num.
$temp = $_POST['number']; >> 0553322111.
?> 

I want to use $temp value that stores the number and modify it to 966553322111 so I can query the records with the new value.

  • 写回答

1条回答 默认 最新

  • dongyuxin5353 2014-06-23 05:55
    关注

    Use preg_replace:

    $phone_number = preg_replace('/^0/','966',$phone_number);
    

    /^0/ = 0 at the start of the string

    So it basically says, replace 0 at the start of the string with 966

    let me know if this works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度