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 can I generate a zip code using Laravel 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 generate fake data in XLSX format using PHP Faker?
- How do I use PHP Faker to generate XML data?
- How do I generate a valid VAT number using Laravel Faker?
- How to generate a title using Laravel Faker?
- How do I check which version of Laravel Faker I am using?
- How do I generate a random zip code using PHP Faker?
- How can I use Faker with Laravel?
See more codes...