Formatting Phone Numbers in PHP

前端 未结 20 2308
面向向阳花
面向向阳花 2020-11-28 19:39

I am working on an SMS app and need to be able to convert the sender\'s phone number from +11234567890 to 123-456-7890 so it can be compared to re

20条回答
  •  不知归路
    2020-11-28 19:57

    I see this being possible using either some regex, or a few substr calls (assuming the input is always of that format, and doesn't change length etc.)

    something like

    $in = "+11234567890"; $output = substr($in,2,3)."-".substr($in,6,3)."-".substr($in,10,4);
    

    should do it.

提交回复
热议问题