php-fakerHow can I generate dummy text with PHP Faker and Lorem Ipsum?
Using PHP Faker and Lorem Ipsum libraries, it is possible to generate dummy text in PHP.
Example code
<?php
require_once 'vendor/autoload.php';
$faker = Faker\Factory::create();
$lorem = new LoremIpsumGenerator;
// Generate a sentence
echo $faker->sentence;
// Generate a paragraph
echo $lorem->getParagraphs(1);
?>
Output
A small river named "Dudley" runs through it.
Pellentesque ut lacus ac purus bibendum hendrerit. Duis eget erat velit. Quisque gravida orci nec nibh viverra, vel aliquam eros aliquet. Aliquam bibendum pharetra velit, in congue nisl egestas vel.
The code above consists of the following parts:
-
require_once 'vendor/autoload.php';
- This line allows us to use the Faker and Lorem Ipsum libraries. -
$faker = Faker\Factory::create();
- This line creates an instance of Faker. -
$lorem = new LoremIpsumGenerator;
- This line creates an instance of Lorem Ipsum. -
echo $faker->sentence;
- This line prints out a sentence generated by Faker. -
echo $lorem->getParagraphs(1);
- This line prints out a paragraph generated by Lorem Ipsum.
Helpful links
More of Php Faker
- How do I generate a zip file using PHP Faker?
- How do I generate a fake year in Laravel using Faker?
- How do I generate a valid VAT number using Laravel Faker?
- How can I generate fake time data using PHP Faker?
- How can I generate fake data in XLSX format using PHP Faker?
- How do I use PHP Faker to generate XML data?
- How can I use Faker with Laravel?
- How do I generate fake state data using PHP Faker?
- How can I generate unique data with Laravel Faker?
- How to generate a title using Laravel Faker?
See more codes...