[man]strlen/man should be of use here. If it has the dashes, it should be 13 characters long. If it doesn't, it should be 10 (or anything but 13). From this, we can conclude that:
if (strlen($string) == 13) {
/* it has the dashes */
}
else {
/* it doesn't. */
}
Now, all you need to do is shove some -s in there. This can be done by using [man]substr/man and concatenating with '-':
$string = substr($string,0,2)
. '-' . substr($string,2,2)
. '-' . substr($string,4,3)
. '-' . substr($string,7,3);