Lorem ipsum generator in PHP without dependencies.
Find a file
Josh Sherman 61f25cb04b
All checks were successful
Test / Test PHP 8.2 (push) Successful in 52s
Test / Test PHP 8.3 (push) Successful in 1m4s
Test / Test PHP 8.4 (push) Successful in 1m2s
Test / Test PHP 8.5 (push) Successful in 1m4s
Merge pull request 'chore: ton of spring cleaning' (#1) from development into master
Reviewed-on: #1
2026-05-12 04:29:41 +00:00
.forgejo/workflows chore: ton of spring cleaning 2026-05-11 23:17:46 -05:00
src chore: ton of spring cleaning 2026-05-11 23:17:46 -05:00
tests feat: ensure passed tags are strings 2022-01-04 22:01:25 -06:00
.gitignore chore: ton of spring cleaning 2026-05-11 23:17:46 -05:00
codecov.yml ci: switch to github actions 2020-06-01 22:25:24 -05:00
composer.json chore: ton of spring cleaning 2026-05-11 23:17:46 -05:00
LICENSE chore: ton of spring cleaning 2026-05-11 23:17:46 -05:00
phpunit.xml chore: ton of spring cleaning 2026-05-11 23:17:46 -05:00
README.md chore: ton of spring cleaning 2026-05-11 23:17:46 -05:00

php-loremipsum

Lorem ipsum generator in PHP without dependencies.

Installation

The preferred installation method is via composer. First add the following to your composer.json:

"require": {
    "joshtronic/php-loremipsum": "^3.0"
}

Then run composer update.

Usage

Getting Started

$lipsum = new joshtronic\LoremIpsum();

Generating Words

echo '1 word: '  . $lipsum->word();
echo '5 words: ' . $lipsum->words(5);

Generating Sentences

echo '1 sentence: '  . $lipsum->sentence();
echo '5 sentences: ' . $lipsum->sentences(5);

Generating Paragraphs

echo '1 paragraph: '  . $lipsum->paragraph();
echo '5 paragraphs: ' . $lipsum->paragraphs(5);

Wrapping Text with HTML Tags

If you would like to wrap the generated text with a tag, pass it as the second parameter:

echo $lipsum->paragraphs(3, 'p');

// Generates: <p>Lorem ipsum...</p><p>...</p><p>...</p>

Multiple tags can also be specified:

echo $lipsum->sentences(3, ['article', 'p']);

// Generates: <article><p>...</p></article><article><p>...</p></article><article><p>...</p></article>

And you can back reference using $1:

echo $lipsum->words(3, '<li><a href="$1">$1</a></li>');

// Generates: <li><a href="...">...</a></li><li><a href="...">...</a></li><li><a href="...">...</a></li>

Return as an Array

Perhaps you want an array instead of a string:

print_r($lipsum->wordsArray(5));
print_r($lipsum->sentencesArray(5));
print_r($lipsum->paragraphsArray(5));

You can still wrap with markup when returning an array:

print_r($lipsum->wordsArray(5, 'li'));

Assumptions

The first string generated will always start with the traditional "Lorem ipsum dolor sit amet, consectetur adipiscing elit". Subsequent strings may contain those words but will not explicitly start with them.

Contributing

Suggestions and bug reports are always welcome, but karma points are earned for pull requests.

Unit tests are required for all contributions. You can run the test suite from the project's root directory simply by running phpunit.

Credits

php-loremipsum was originally inspired by badcow/lorem-ipsum with a goal of being a dependency free lorem ipsum generator with flexible generation options.

License

GPLv3