fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. $phone = fgets(STDIN);
  6. $i = 1; $k = 0;
  7. $new_phone = '';
  8. for ($i = 0; $i <= strlen($phone)-1; $i++){
  9. if (is_numeric(substr($phone, $i, 1))) {$new_phone .= substr($phone, $i, 1); $k++;}
  10. if (($k > 2) && ($k % 3) == 0) {$new_phone .= '-'; $k = 0;}
  11. }
  12. fwrite(STDOUT, $new_phone);
  13.  
  14. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
9 - 33 2176--856
stdout
933-217-685-6