Generate US Phone Numbers With PHP ?

Mutt

Professional
Messages
1,458
Reaction score
1,296
Points
113
Code:
function generate_number(){
  $number = "1";
  $number .= "-".rand(2,9).rand(2,9).rand(2,9)."-".rand(2,9).rand(0,9).rand(0,9)."-".rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  return $number;
}

$number = generate_number();
echo $number;

Example Output :
1-875-513-2962

While I was programming I kept coming across phone numbers from that particular page and then I thought, would it be better to display a randomly generated number? What if the person calls support and asks for help? Well here I have created a small script on the basic US format of phone numbers.
 
Top