For a decent and standardized php function I want to format a user inputted string to a std. international phone number format. The string will be stripped from other characters as digits and +-signs. All spaces will be deleted. After that I want to format the different strings to a standardized form:
+310612345678  -> +31 (0)61 234 5678
00310612345678  -> +31 (0)61 234 5678
+31612345678   -> +31 (0)61 234 5678 
//add a leading zero between brackets (0))
0031612345678  -> +31 (0)61 234 5678
06 12345678   -> +31 (0)61 234 5678 
//When no country code is given (no 00xx or +xx) than add the dutch one.
This is the function which i have allready:
function formatPhoneNumber($num){
 //delete everything except digits and +
  $number = preg_replace('/[^\d|\+]/', '', $number);
 if(substr($number,0,1) == '+' || substr($number, 0,2) == 00){
  //
 }else{
  $number = "+31".$number;
 }
 /////////
 // formatting as mentioned above
 /////////
 return $num
}
I'm Looking for a algorithm to format the different ways of user inputted telephone numbers to one format: +31 (0)61 2345678