BeautySlug is a lightweight, flexible PHP library for generating beautiful, readable slugs.
Install via Composer:
composer require teariot/beautyslug
use BeautySlug\BeautySlug;
use BeautySlug\SlugWords;
// Basic random slug
echo BeautySlug::slug();
// Example: wonderful-tree
// Slug with a color and an animal
echo BeautySlug::slug([
SlugWords::color(1),
SlugWords::animal(1),
]);
// Example: blue-lion
// Slug with digits appended
echo BeautySlug::slug([
SlugWords::adjective(1),
SlugWords::noun(1),
], [
'appendDigits' => true,
'digitsCount' => 5,
]);
// Example: fancy-robot-48291
Option | Type | Description | Default |
---|---|---|---|
separator |
string |
Separator between words | - |
appendDigits |
bool |
Append random digits at the end | false |
digitsCount |
int |
Number of digits to append if enabled | 4 |
You can override options by passing an array as the second parameter to slug()
.
BeautySlug uses predefined word lists:
adjective
noun
color
season
emoji
verb
animal
cosmos
You can directly access random words:
SlugWords::adjective(2); // Get 2 random adjectives
SlugWords::noun(1); // Get 1 random noun
SlugWords::color(1); // Get 1 random color
See the examples/usage.php
file for more examples.
To run:
php examples/usage.php
Released under the MIT License.
Built with ❤️ by Teariot