php-fakerHow do I format a phone number using PHP Faker?
To format a phone number using PHP Faker, you can use the $faker->phoneNumber
method. This method will return a random phone number in the format of (###) ###-####
.
<?php
$faker = Faker\Factory::create();
$phoneNumber = $faker->phoneNumber;
echo $phoneNumber;
// Output: (819) 675-4337
?>
The code consists of three parts:
$faker = Faker\Factory::create();
- This line instantiates a Faker object.$phoneNumber = $faker->phoneNumber;
- This line assigns a random phone number to the$phoneNumber
variable.echo $phoneNumber;
- This line prints the phone number to the screen.
For more information on formatting phone numbers using PHP Faker, please refer to the documentation.
More of Php Faker
- How do I generate a random digit using PHP Faker?
- How do I generate a zip file using PHP Faker?
- How do I generate a fake year in Laravel using Faker?
- How can I use Faker in PHP to generate fake data?
- How can I generate unique data with Laravel Faker?
- How can I generate a zip code using Laravel Faker?
- How can I use Faker with Laravel?
- How can I generate fake values using Laravel Faker?
- How can I generate a fake URL using PHP Faker?
- How can I use Laravel Faker to generate nullable values?
See more codes...