"Vincent's solutions is actually more elegnt, though it may not appear easier🙂"
:-)
let me explain for those who do not understand:
$sNum = preg_replace("/([0-9]{3})(.*)/", "\1-\2", $sNum);
The first parameter defines a 'pattern' which describes what I am looking for.
The second parameter defines what I want to replace every occurence of the pattern with.
The third parameter defined the string in which I want to replace.
The pattern consists of two slashes which define the beginning and the end of the pattern. Inside the slashes I have two sets of parentheses. These define blocks that I can refer to later.
The first block is for the first three digits. [0-9]{3} the [0-9] means 'any number between 0 and 9 and the {3} means 'must appear three times in a row; so it will match a sequence of three numbers (000 through 999)
The second block is simple: (.*) the dot means means 'any character' and the star means 'zero or more times' so this matches anything, or 'whatever is left'
So the pattern will match on a sequence of three numbers, followed by anything (even nothing).
The second parameter contains 'backreferences'.
"\1-\2" the \1 and \2 refer to the blocks from the first pattern. \1 will contain the string that matched on the first block of the pattern, the three-number sequence. \2 will contain the match of (.*)
so "\1\2" would give the original string back.
But I want a dash between the first three numbers and the rest, so I put a dash between the \1 and the \2.
that's all folks.