Search code examples
phpnumberspreg-replacetwilionumber-formatting

How to add dots between numbers using preg_replace?


I'm using a phone API called Twilio and it does text to voice. I'm making a phone number verification script that makes a 'PIN' and calls the user and gives them the pin thing is the voice API says it like the words, eg. PIN: 2001 would make it say "two thousand and one".

I was thinking if I put dots between them like PIN: 2001 -> 2.0.0.1 it would change that, I'm guessing I would have to preg_replace but I have no idea what expression would be used.

This is how I am generating my PIN:

$pin = substr(str_shuffle('1234567890'), 0, 4);

Solution

  • how about something like this:

    implode(".", str_split($pin))