PHP Packagev8.0.xMIT License8.2K+ downloads

Slugify: Clean slugs in every language

Turn "مرحبا بالعالم", "Crème brûlée" or "XMLHttpRequest" into a clean URL slug with one Slugify::make() call. It keeps Unicode, or transliterates to ASCII when you ask.

$composer require pharaonic/php-slugify
Key Features

Everything you need to build URL slugs

One static call for everyday use, plus a fluent builder when you need more control.

Unicode First

Arabic, Persian, Cyrillic, Greek, CJK and Indic scripts are kept as-is, and Arabic diacritics are stripped.

ASCII Transliteration

Call ->ascii() or ->ascii('de') for Latin-only slugs, powered by voku/portable-ascii.

Smart Word Splitting

XMLHttpRequest becomes xml-http-request, and getUserID becomes get-user-id.

Any Separator

Use -, _, ., ~, an empty string, or your own. Repeats are collapsed automatically.

Replacement Rules

Add package-wide rules with Slugify::addRule(), or rules for one slug only with ->rule().

Backward Compatible

slug(), Slugify::get() and Slugify::rule() from 2.x keep working.

A quick look

Unicode by default, ASCII on demand, and a fluent builder when you need it.

app/Support/Permalinks.php
1use Pharaonic\Slugify\Slugify;
2 
3Slugify::make('Hello World'); // hello-world
4Slugify::make('مرحبا بالعالم'); // مرحبا-بالعالم
5Slugify::make('Crème brûlée', '-', true); // creme-brulee
6 
7Slugify::of('Äpfel & Öl im XMLHttpRequest')
8 ->ascii('de')
9 ->rule('&', ' and ')
10 ->maxLength(30)
11 ->toString(); // aepfel-and-oel-im-xml-http
FAQ

Slugify Questions

Quick answers about installing and using Slugify.

What is Slugify?

Framework-agnostic slug generation for PHP. Keep Unicode or transliterate to ASCII, use any separator, split camelCase and acronyms, and add your own replacement rules. It's a free, open-source PHP package by Pharaonic.

How do I install Slugify?

Run composer require pharaonic/php-slugify in your project's root directory.

What does Slugify require?

The latest release requires PHP 8.0+.

Does Slugify support Arabic and other non-Latin scripts?

Yes. By default, slugs keep Unicode letters, so مرحبا بالعالم becomes مرحبا-بالعالم. Pass true as the third argument to Slugify::make() to transliterate to ASCII instead.

Does it depend on Laravel or another framework?

No. Slugify is plain PHP with no framework, container or config files. For Eloquent models, use the companion package pharaonic/laravel-sluggable.

How do I customize how characters are replaced?

Add package-wide rules with Slugify::addRule('&', ' and '), or rules for one slug only with Slugify::of($title)->rule('&', ' and ').

Is Slugify free to use?

Yes. Slugify is open source under the MIT license, so you can use it in personal and commercial projects.

Where can I find the Slugify documentation?

Read the Slugify documentation for setup and usage examples.

How do I report a bug or contribute to Slugify?

Open an issue or a pull request on GitHub, or ask in the Pharaonic Discord.

Ready to dig in?

Read the full documentation for installation, Unicode and ASCII slugs, separators, replacement rules, the fluent API, custom transliterators, and upgrading from 2.x.