<?php
function mascaraTelefone($numero){
$numero = str_pad($numero, 8, '0', STR_PAD_LEFT
); return $numero;
}
/*
Versão alternativa
function mascaraTelefone($numero){
$numero = str_pad($numero, 8, '0', STR_PAD_LEFT);
return substr_replace($numero, '-', 4, 0);
}
*/
echo mascaraTelefone('9999') .PHP_EOL;
echo mascaraTelefone('99998888') .PHP_EOL;
echo mascaraTelefone('77') .PHP_EOL;
echo mascaraTelefone('666') .PHP_EOL;
PD9waHAKCmZ1bmN0aW9uIG1hc2NhcmFUZWxlZm9uZSgkbnVtZXJvKXsKCSRudW1lcm8gPSBzdHJfcGFkKCRudW1lcm8sIDgsICcwJywgU1RSX1BBRF9MRUZUKTsKCSRudW1lcm8gPSB0cmltKGNodW5rX3NwbGl0KCRudW1lcm8sIDQsICctJyksICctJyk7CglyZXR1cm4gJG51bWVybzsKfQogICAgIAovKgpWZXJzw6NvIGFsdGVybmF0aXZhCmZ1bmN0aW9uIG1hc2NhcmFUZWxlZm9uZSgkbnVtZXJvKXsKICAgICRudW1lcm8gPSBzdHJfcGFkKCRudW1lcm8sIDgsICcwJywgU1RSX1BBRF9MRUZUKTsKICAgIHJldHVybiBzdWJzdHJfcmVwbGFjZSgkbnVtZXJvLCAnLScsIDQsIDApOwp9CiovCiAgICAKZWNobyBtYXNjYXJhVGVsZWZvbmUoJzk5OTknKSAuUEhQX0VPTDsKZWNobyBtYXNjYXJhVGVsZWZvbmUoJzk5OTk4ODg4JykgLlBIUF9FT0w7CmVjaG8gbWFzY2FyYVRlbGVmb25lKCc3NycpIC5QSFBfRU9MOwplY2hvIG1hc2NhcmFUZWxlZm9uZSgnNjY2JykgLlBIUF9FT0w7