-3

There are a couple formatting scripts out there but not what I'm looking for. ex: 400777666555 what I want: +400 777 666 555 So to add a + and make spaces every 3 numbers.

$number = get_the_author_meta('mobile');
$split = chunk_split($number, 3);
$num = "+" . implode(" ", $split);

The code works only if I delete the last $num line. Not sure what's wrong. If I delete it, it works fine, just without the +.

Kara
  • 6,115
  • 16
  • 50
  • 57
Fid
  • 462
  • 4
  • 21

1 Answers1

2

I just searched on Google for a couple minutes and found this answer. I strongly suggest you do some research on any PHP questions first, because with PHP there are tons of random utility methods that most people don't know about until they search directly for it.

$number = "400777666555";
$array = chunk_split($number, 3);
$output = "+" . implode(" ", $array);

Also, on StackOverflow, it's preferred if you add some code to your question to show what you have tried.

  • Thank you, I'll do more research next time. I usually have a basic idea where to start, never heard of chunk_split. – Fid Mar 14 '13 at 21:39
  • No problem at all. Glad I could help! –  Mar 14 '13 at 21:45