Saltar al contenido

ejemplo de código de uso de php faker

Ejemplo: php faker

Installation#
Faker requires PHP >= 7.1.


composer require fakerphp/faker
Basic Usage#
Autoloading#
Faker supports both PSR-0 as PSR-4 autoloaders.


// when installed via composer
require_once 'vendor/autoload.php';
You can also load Fakers shipped PSR-0 autoloader


// load Faker autoloader
require_once '/path/to/Faker/src/autoload.php';
alternatively, you can use any other PSR-4 compliant autoloader

Create fake data#
Use FakerFactory::create() to create and initialize a faker generator, which can generate data by calling methods named after the type of data you want.


require_once 'vendor/autoload.php';

// use the factory to create a FakerGenerator instance
$faker = FakerFactory::create();
// generate data by calling methods
echo $faker->name();
// 'Vince Sporer'
echo $faker->email();
// '[email protected]'
echo $faker->text();
// 'Numquam ut mollitia at consequuntur inventore dolorem.'
Each call to $faker->name() yields a different (random) result. This is because Faker uses __call() magic, and forwards FakerGenerator->$method() calls to FakerGenerator->format($method, $attributes).


for ($i = 0; $i < 3; $i++) {
    echo $faker->name() . "n";
}

// 'Cyrus Boyle'
// 'Alena Cummerata'
// 'Orlo Bergstrom'
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada.