# PHP Slugify documentation (v8.6.x)

> Canonical: https://pharaonic.dev/packages/php/slugify/8.6.x  
> Version: v8.6.x (latest release 8.6.0, 2026-12-01)  
> Install: composer require pharaonic/php-slugify  
> Requires: PHP 8.6  
> Repository: https://github.com/Pharaonic/php-slugify  
> All versions: https://pharaonic.dev/packages/php/slugify/8.6.x.md https://pharaonic.dev/packages/php/slugify/8.5.x.md https://pharaonic.dev/packages/php/slugify/8.4.x.md https://pharaonic.dev/packages/php/slugify/8.3.x.md https://pharaonic.dev/packages/php/slugify/8.2.x.md https://pharaonic.dev/packages/php/slugify/8.1.x.md https://pharaonic.dev/packages/php/slugify/8.0.x.md

:::badges
- PHP Package {color=blue}
- v8.6.0 {color=green}
- MIT License {color=purple}
:::

# PHP Slugify

Fast, framework-agnostic slug generation for PHP. Turn any string into a URL-friendly slug. By default it keeps Unicode letters as they are. ASCII is opt-in, locales only change language-specific behavior, and symbols, emoji and numbers each follow an explicit policy. Same input, same slug, every time.

:::features
### Unicode First
Arabic, Cyrillic, Greek, CJK and other scripts stay as they are, so slugs read naturally in their own language.

### ASCII on Demand
Transliterate to Latin-only slugs when you need them, with optional locale rules for languages such as German or Ukrainian.

### Explicit Policies
Symbols, emoji and Unicode numbers are handled on purpose, not by accident, with no invisible residue.
:::

:::info Quick Tip
`Slugify::make()` covers most needs. Reach for `Slugify::of()` when you want a fluent, immutable builder with `maxLength()`, per-slug rules, or a custom transliterator.
:::

## Installation

Install the package with Composer. There is nothing to register or publish.

### Requirements

- PHP 8.6.x (each `8.x` release line targets the matching PHP version)
- `ext-mbstring`
- `voku/portable-ascii` ^2.0.2 and `symfony/polyfill-intl-normalizer` (installed automatically)
- `ext-intl` *(optional)*: Unicode normalization works without it, but the native extension is faster than the polyfill.

### Composer Installation

```bash title="Terminal" no-line-numbers
composer require pharaonic/php-slugify
```

Composer autoloads the `Pharaonic\Slugify` namespace and the global `slug()` helper.

:::success Installation Complete
You're all set! Try `Slugify::make('Hello World')`, which returns `hello-world`.
:::

## Basic Usage

Import the `Slugify` class and call `make()`:

```php
use Pharaonic\Slugify\Slugify;

Slugify::make('Hello World');            // "hello-world"
Slugify::make('  Hello   World!!  ');    // "hello-world"
Slugify::make('hello - _ world');        // "hello-world"
Slugify::make('Top 10 Tips for 2026');   // "top-10-tips-for-2026"
```

The full signature is `make(string $value, string $separator = '-', bool $ascii = false, ?string $language = null)`. `$language` is the [locale](#locales):

```php
Slugify::make('Hello World', '_');                // "hello_world"
Slugify::make('Crème brûlée', '-', true);         // "creme-brulee"
Slugify::make('Äpfel und Öl', '-', true, 'de');   // "aepfel-und-oel"
```

### The `slug()` Helper

The global helper takes the same arguments. It also accepts any scalar or `Stringable` value, and `null` gives an empty string.

```php
slug('Hello World');                // "hello-world"
slug('Hello World', '_', true);     // "hello_world"
slug(2026);                         // "2026"
slug(null);                         // ""
```

### How a Slug Is Built

Each call runs the same deterministic steps in order. Every step can be inspected with [`explain()`](#fluent-api).

1. **Unicode normalization**: repair invalid UTF-8, turn control characters into word breaks, normalize to NFC and fold presentation forms (`ﬁ` → `fi`).
2. **CamelCase splitting**: `helloWorld` → `hello World`.
3. **Replacement rules**: your rules, before anything else changes the text.
4. **Numbers**: `١٢`, `۱۲`, `①②` → `12`.
5. **Emoji policy**: removed by default, as whole sequences.
6. **Symbol policy**: removed by default.
7. **Lowercasing**, locale-aware (`tr`: `I` → `ı`).
8. **Transliteration** (ASCII mode only): locale overrides, then portable-ascii. In ASCII mode, rules made of ASCII words (`allh` → `allah`) run right after this step.
9. **Filtering**: invisible characters are dropped. Letters, numbers and combining marks are kept (only `[A-Za-z0-9]` in ASCII mode).
10. **Joining**: words joined with the separator, within `maxLength()` if set.

Empty results are returned as `""`. `"0"` is treated as real input and gives `"0"`.

## Unicode & ASCII

Slugify is **Unicode-first**: by default a slug keeps the letters of every script. ASCII output is something you ask for explicitly.

### Unicode Slugs (Default)

Unicode letters, numbers and combining marks are kept. Punctuation, symbols and whitespace become separators, and emoji are removed.

```php
Slugify::make('مرحبا بالعالم');      // "مرحبا-بالعالم"
Slugify::make('سلام دنیا');          // "سلام-دنیا"
Slugify::make('Привет, мир!');       // "привет-мир"
Slugify::make('Γειά σου Κόσμε');     // "γειά-σου-κόσμε"
Slugify::make('你好，世界');           // "你好-世界"
Slugify::make('नमस्ते दुनिया');         // "नमस्ते-दुनिया"
Slugify::make('Laravel مع PHP');     // "laravel-مع-php"
Slugify::make('PHP 🚀 Rocks');        // "php-rocks"
```

Arabic diacritics (tashkeel), the tatweel and Hebrew points (niqqud) are removed in every mode, and the alef wasla (`ٱ`) becomes a plain alef, so vocalized and plain spellings give the same slug:

```php
Slugify::make('مُحَمَّد');             // "محمد"
Slugify::make('مـحـمـد');             // "محمد"
Slugify::make('ٱلْحَمْدُ');            // "الحمد"
```

### ASCII Slugs

Pass `true` as the third argument, or call `->ascii()` on the fluent builder. Transliteration is handled by [voku/portable-ascii](https://github.com/voku/portable-ascii), plus a few curated [locale overrides](#locales).

```php
Slugify::make('Crème brûlée', '-', true);   // "creme-brulee"
Slugify::make('Привет мир', '-', true);     // "privet-mir"
Slugify::make('مرحبا', '-', true);          // "mrhba"
Slugify::make('你好世界', '-', true);         // "ni-hao-shi-jie"
Slugify::make('한국어', '-', true);           // "hangugeo"

Slugify::of('Crème brûlée')->ascii()->toString();   // "creme-brulee"
```

ASCII mode always returns `[a-z0-9]` words joined by your separator (`[A-Za-z0-9]` with `lowercase(false)`). Characters that can't be transliterated are dropped.

The text is lowercased **before** it is transliterated, so the result never depends on the input's case: `Χαρά`, `χαρά` and `ΧΑΡΆ` all give the same slug.

:::info Transliteration is not romanization
ASCII mode makes readable, deterministic slugs. It is not a linguistic romanization engine: unvocalized scripts such as Arabic and Hebrew lose information, and Japanese kanji are read as Chinese. If you need a specific standard, add [rules](#rules) or a [custom transliterator](#extending).
:::

### Unicode Normalization

Every slug starts from well-formed, canonical text. This works the same with or without `ext-intl`, because the package requires `symfony/polyfill-intl-normalizer`.

- **NFC**: `e` + U+0301 and `é` give the same slug in both modes.
- **Presentation forms** are folded to the letters they display: ligatures (`ﬁ` → `fi`), full-width and half-width forms (`Ｈｅｌｌｏ` → `hello`, `ｶﾀｶﾅ` → `カタカナ`), Arabic presentation forms, and mathematical alphanumerics (`𝐇𝐞𝐥𝐥𝐨` → `hello`).
- Symbols with a compatibility form, such as `™` or `½`, are **not** folded. They follow the [symbol policy](#symbols-and-emoji).
- **Invalid UTF-8**, control characters, null bytes and the zero-width space become word breaks.
- **Invisible characters** never reach the slug: zero-width joiners, soft hyphens, bidi marks, the BOM and variation selectors are removed. A soft hyphen or a Persian ZWNJ inside a word doesn't split it: `می‌خواهم` → `میخواهم`.

## Locales

A locale selects **language-specific behavior**. It never turns ASCII output on by itself:

- **locale**: how language-specific behavior works.
- **ascii**: whether the output must be ASCII.

```php
Slugify::of('Äpfel Straße')->locale('de')->toString();           // "äpfel-straße"
Slugify::of('Äpfel Straße')->locale('de')->ascii()->toString();  // "aepfel-strasse"
Slugify::of('Äpfel Straße')->ascii()->toString();                // "apfel-strasse"
```

`ascii('de')` is a shorthand for `locale('de')->ascii()`, and `make()` takes the locale as its fourth argument:

```php
Slugify::of('München')->ascii('de')->toString();   // "muenchen"
Slugify::make('München', '-', true, 'de');         // "muenchen"
```

Locale codes can include a region or script: `de-DE`, `de_AT`, `sr-Latn` and `uk-UA` all work. If portable-ascii has a regional variant (`de-AT` writes `ß` as `sz`), it is used. Otherwise the base language applies. Unknown or malformed codes fall back to the generic behavior.

### In Unicode Mode

Turkish and Azerbaijani have a dotless `ı`, so their capital `I` lowercases differently:

```php
Slugify::make('IŞIK');                         // "işik"
Slugify::of('IŞIK')->locale('tr')->toString(); // "ışık"
Slugify::of('IŞIQ')->locale('az')->toString(); // "ışıq"
```

### In ASCII Mode

The locale is passed to portable-ascii, which has maps for dozens of languages. Pharaonic adds an override **only** where the generic result is demonstrably wrong:

| Locale | Generic result | With the locale | Pharaonic override |
| --- | --- | --- | --- |
| `de` German | `apfel` | `aepfel` | No (portable-ascii) |
| `sr` Serbian | `shabats`, `dorde` | `sabac`, `djordje` | No (portable-ascii) |
| `uk` Ukrainian | `kiyiv`, `zuk` | `kyiv`, `zhuk` | **Yes**: the official 2010 national system |
| `tr`, `az`, `pl`, `ro`, `vi` | already correct | — | No |
| `ru`, `el`, `ar`, `fa`, `he`, `hy`, `ka`, `zh`, `ja`, `ko`, `my` | deterministic and readable | — | No |

```php
Slugify::of('Київ Запоріжжя Щастя')->ascii('uk')->toString();
// "kyiv-zaporizhzhia-shchastia"
```

Your own [rules](#rules) always win over locale overrides, which win over the generic transliterator:

```php
Slugify::of('Київ')->ascii('uk')->rule('київ', 'kiev')->toString();   // "kiev"
```

:::info Requesting a locale override
Overrides live in `src/Resources/locales/` and each needs a sample in the test corpus (`tests/Fixtures/Transliteration/`) where the generic result fails. The test suite rejects an override that the corpus doesn't justify.
:::

## Symbols, Emoji & Numbers

Symbols, emoji and numbers each have their own explicit, independent policy.

### Symbols

By default, symbols are removed and act as word breaks:

```php
Slugify::make('R&D');           // "r-d"
Slugify::make('50% off');       // "50-off"
Slugify::make('Acme™ Pro');     // "acme-pro"
```

The one exception is the historical `@` → `at` [default rule](#rules): `user@host` → `user-at-host`.

Choose another policy with `symbols()`:

```php
use Pharaonic\Slugify\Policies\SymbolPolicy;

Slugify::of('R&D')->symbols(SymbolPolicy::words())->toString();       // "r-and-d"
Slugify::of('50% off')->symbols(SymbolPolicy::words())->toString();   // "50-percent-off"
Slugify::of('€100')->symbols(SymbolPolicy::words())->toString();      // "euro-100"

Slugify::of('R&D')->locale('de')->symbols(SymbolPolicy::words())->toString();   // "r-und-d"

Slugify::of('C# & C++')
    ->symbols(SymbolPolicy::custom(['#' => 'sharp', '+' => 'plus']))
    ->toString();                                                       // "c-sharp-c-plus-plus"
```

| Policy | Behavior |
| --- | --- |
| `SymbolPolicy::remove()` | Default. Symbols become word breaks. |
| `SymbolPolicy::words()` | Spells symbols out in the slug's locale (English fallback): `& + = %`, currencies, `© ® ™ @`. Words come from portable-ascii. `#` is not spelled out because its meaning varies (`C#`, `#1`). |
| `SymbolPolicy::custom(array $map)` | Spells out only the symbols you list. Others are removed. |

Replacement words are always separate words in the slug.

### Emoji

Emoji are removed by default, always as whole sequences. Skin tones, ZWJ families, flags, keycaps and variation selectors never leave invisible characters behind:

```php
Slugify::make('PHP 🚀 Rocks');     // "php-rocks"
Slugify::make('I ❤️ PHP');          // "i-php"
Slugify::make('👨‍👩‍👧‍👦 family');      // "family"
Slugify::make('Egypt 🇪🇬');        // "egypt"
```

To turn emoji into words, provide your own words. The package ships no emoji names:

```php
use Pharaonic\Slugify\Policies\EmojiPolicy;

$emoji = EmojiPolicy::custom(['🚀' => 'rocket', '👍' => 'thumbs up', '🇪🇬' => 'egypt']);

Slugify::of('PHP 🚀 Rocks')->emoji($emoji)->toString();   // "php-rocket-rocks"
Slugify::of('👍🏽')->emoji($emoji)->toString();            // "thumbs-up"
```

A custom word matches an emoji with any skin tone or presentation selector. Emoji you don't list are removed.

:::info "©" vs "©️"
`©` is a symbol and follows the symbol policy. `©️` (with the emoji variation selector) is an emoji and follows the emoji policy.
:::

### Numbers

Digits from any script, and unambiguous numeric forms, are converted to ASCII digits, in both Unicode and ASCII mode:

```php
Slugify::make('الإصدار ١٢');   // "الإصدار-12"  (Arabic-Indic)
Slugify::make('نسخه ۱۲');      // "نسخه-12"     (Persian)
Slugify::make('１２３');        // "123"         (full-width)
Slugify::make('①②③');         // "123"         (circled)
Slugify::make('H₂O');          // "h2o"         (subscript)
Slugify::make('10 m²');        // "10-m2"       (superscript)
Slugify::make('Top 1️⃣');       // "top-1"       (keycap)
```

Arabic-Indic `٣` and Persian `۳` look alike but are different characters. Normalizing both gives one slug for the same title.

Forms whose meaning isn't a plain number are left alone: fractions (`½`), Roman numerals (`Ⅻ`) and numbers without a decomposition (`❶`). An exponent never merges into its base: `10²` → `10-2`, not `102`.

Turn the conversion off with `normalizeNumbers(false)`:

```php
Slugify::of('الفصل ٣')->normalizeNumbers(false)->toString();   // "الفصل-٣"
```

## Separators

The second argument of `make()`, or `separator()` on the builder, sets the string that joins words. The default is `-`.

```php
Slugify::make('Hello World', '-');   // "hello-world"
Slugify::make('Hello World', '_');   // "hello_world"
Slugify::make('Hello World', '.');   // "hello.world"
Slugify::make('Hello World', '~');   // "hello~world"
Slugify::make('Hello World', '');    // "helloworld"
```

Dashes, underscores, dots and other punctuation already in the input are treated as word breaks. Repeats are collapsed, and the slug never starts or ends with a separator:

```php
Slugify::make('-hello__big.. ~world-', '_');   // "hello_big_world"
Slugify::make('hello---world');                // "hello-world"
Slugify::make('---');                          // ""
```

:::warning Invalid Separators
A separator must not contain letters, numbers, combining marks or whitespace. For example, `'x'`, `'1'` and `' '` throw `Pharaonic\Slugify\Exceptions\InvalidArgumentException`.
:::

## CamelCase & Acronyms

Words written in camelCase or PascalCase are split before slugging. Runs of capitals are kept together as acronyms.

```php
Slugify::make('helloWorld');        // "hello-world"
Slugify::make('HelloWorld');        // "hello-world"
Slugify::make('XMLHttpRequest');    // "xml-http-request"
Slugify::make('APIResponse');       // "api-response"
Slugify::make('getUserID');         // "get-user-id"
Slugify::make('PharaonicPHP');      // "pharaonic-php"
Slugify::make('Version2Beta');      // "version2-beta"
Slugify::make('3D Printing');       // "3d-printing"
Slugify::make('ÉtéÀParis');         // "été-à-paris"
```

The splitting rules are:

- A lowercase letter followed by an uppercase letter starts a new word (`helloWorld`).
- An uppercase letter or digit followed by a capitalized word starts a new word (`XMLHttp`, `2Beta`).
- A digit followed by a lone capital doesn't split (`3D`, `5G`).

Turn splitting off for a single slug with `splitCamelCase(false)`:

```php
Slugify::of('helloWorld')->splitCamelCase(false)->toString();   // "helloworld"
```

## Replacement Rules

Rules replace text before the slug is built. Replacements are literal, so add spaces when the replacement should be its own word.

### Package-wide Rules

```php
Slugify::addRule('&', ' and ');
Slugify::make('Tom & Jerry');    // "tom-and-jerry"

Slugify::addRules([
    'ö' => 'oe',
    'ü' => 'ue',
    'ä' => 'ae',
]);
Slugify::make('Äpfel Öl');       // "aepfel-oel"
```

Package-wide rules are global static state. Register them once during your app's bootstrap, for example in a Laravel service provider's `boot()` method.

### Per-slug Rules

Rules added on the fluent builder apply to that slug only:

```php
Slugify::of('500$ Bill')->rule('$', ' dollar ')->toString();   // "500-dollar-bill"
Slugify::make('500$ Bill');                                      // "500-bill"

Slugify::of('C++ & C#')
    ->rules(['c++' => 'cpp', '&' => ' and ', 'c#' => 'csharp'])
    ->toString();                                                // "cpp-and-csharp"
```

### Default Rule

The package ships with one default rule, kept from 2.x:

| Rule | Purpose |
| --- | --- |
| `@` → ` at ` | `user@host` → `user-at-host` |

Override or remove it like any other rule:

```php
Slugify::addRule('@', ' chez ');   // override
Slugify::removeRule('@');          // remove
Slugify::resetRules();             // restore the package defaults
Slugify::rules()->all();           // inspect: ['@' => ' at ']
```

Other symbols are handled by the [symbol policy](#symbols-and-emoji). Arabic tashkeel and Hebrew points are removed by [Unicode normalization](#unicode-and-ascii), not by rules.

To ignore every default and package-wide rule for one slug, call `withoutRules()`:

```php
Slugify::of('user@host')->withoutRules()->toString();   // "user-host"
```

### How Rules Match

- **Case**: when the slug is lowercased (the default), rules match case-insensitively. With `lowercase(false)` they match exactly.
- **Single pass**: all rules are applied at once and the longest search string wins. A replacement is never re-processed by another rule.
- **Overrides**: adding a rule with an existing search string replaces it, and per-slug rules override package-wide ones.
- **Precedence**: rules run before numbers, emoji, symbols, locale overrides and transliteration, so your rules always win.
- **ASCII mode**: rules made only of ASCII letters, digits, spaces, `_`, `.` and `-` (`allh` → `allah`) run *after* transliteration, so they also match transliterated text. Every other rule (`ö`, `$`, `c++`) runs first.

```php
Slugify::addRule('allh', 'allah');
Slugify::make('بسم الله', '-', true);   // "bsm-allah"
```

## Fluent API

`Slugify::of()` returns a `Pharaonic\Slugify\Slugger`. The builder is immutable: every method returns a new instance, so you can configure one base builder and reuse it.

```php
use Pharaonic\Slugify\Slugify;

Slugify::of('Hello World')
    ->separator('_')
    ->lowercase()
    ->toString();                       // "hello_world"

(string) Slugify::of('Hello World');    // "hello-world"
```

### Reusing a Builder

```php
$base = Slugify::of('Hello World');

$base->separator('_')->toString();      // "hello_world"
$base->ascii()->toString();             // "hello-world"
$base->toString();                      // "hello-world" (unchanged)
```

### Locale and Policies

```php
use Pharaonic\Slugify\Policies\EmojiPolicy;
use Pharaonic\Slugify\Policies\SymbolPolicy;

Slugify::of('R&D 🚀 Straße')
    ->locale('de')
    ->ascii()
    ->symbols(SymbolPolicy::words())
    ->emoji(EmojiPolicy::custom(['🚀' => 'rakete']))
    ->toString();                       // "r-und-d-rakete-strasse"
```

See [Locales](#locales) and [Symbols, Emoji & Numbers](#symbols-and-emoji).

### Limiting the Length

`maxLength()` limits the slug to a number of characters, cutting on a word boundary, so it never ends with a separator. A single word longer than the limit is truncated between whole characters, so a letter never loses its accents or vowel signs.

```php
Slugify::of('The quick brown fox jumps')->maxLength(15)->toString();   // "the-quick-brown"
Slugify::of('The quick brown fox jumps')->maxLength(14)->toString();   // "the-quick"
Slugify::of('Supercalifragilistic')->maxLength(5)->toString();         // "super"
```

### Keeping Case

```php
Slugify::of('Hello World')->lowercase(false)->toString();             // "Hello-World"
Slugify::of('Crème Brûlée')->lowercase(false)->ascii()->toString();   // "Creme-Brulee"
```

### Options Object

All options can be passed at once with `SlugOptions`. Named arguments keep it readable:

```php
use Pharaonic\Slugify\Policies\SymbolPolicy;
use Pharaonic\Slugify\SlugOptions;

$options = new SlugOptions(separator: '_', ascii: true, language: 'de', maxLength: 60);

Slugify::of('München ist schön', $options)->toString();   // "muenchen_ist_schoen"

$options = new SlugOptions(symbols: SymbolPolicy::words(), normalizeNumbers: false);
```

### Explaining a Slug

`explain()` returns the text after every step of the pipeline, as structured data. Use it to debug a surprising slug. `toString()` runs the same steps without recording them.

```php
Slugify::of('Äpfel & Straße 🚀')->locale('de')->ascii()->explain();

// [
//     'original'            => 'Äpfel & Straße 🚀',
//     'unicode_normalized'  => 'Äpfel & Straße 🚀',
//     'camel_case_split'    => 'Äpfel & Straße 🚀',
//     'custom_replacements' => 'Äpfel & Straße 🚀',
//     'numbers_normalized'  => 'Äpfel & Straße 🚀',
//     'emoji_processed'     => 'Äpfel & Straße  ',
//     'symbols_processed'   => 'Äpfel & Straße  ',
//     'lowercased'          => 'äpfel & straße  ',
//     'transliterated'      => 'aepfel & strasse  ',
//     'ascii_replacements'  => 'aepfel & strasse  ',
//     'filtered'            => 'aepfel strasse',
//     'final'               => 'aepfel-strasse',
// ]
```

:::info Global Rules Are Captured
`Slugify::of()` captures the package-wide rules when it is called. Rules added later with `Slugify::addRule()` don't affect builders that already exist.
:::

## Extending

### Custom Transliterator

ASCII transliteration goes through the `Pharaonic\Slugify\Contracts\Transliterator` interface. The default is `LocaleAwareTransliterator`, which applies the curated [locale overrides](#locales) and passes everything else to `PortableAsciiTransliterator`. Implement the interface to use another engine, such as ICU:

```php title="app/Support/IntlTransliterator.php"
namespace App\Support;

use Pharaonic\Slugify\Contracts\Transliterator;

final class IntlTransliterator implements Transliterator
{
    public function transliterate(string $value, ?string $language = null): string
    {
        return \Transliterator::create('Any-Latin; Latin-ASCII')->transliterate($value);
    }
}
```

Use it for every slug, or for a single one:

```php
use App\Support\IntlTransliterator;
use Pharaonic\Slugify\Slugify;

Slugify::useTransliterator(new IntlTransliterator());   // package-wide

Slugify::of('Привет')
    ->ascii()
    ->transliterator(new IntlTransliterator())          // this slug only
    ->toString();

Slugify::useTransliterator(null);                       // restore the default
```

The transliterator only runs in ASCII mode, and receives the locale as `$language`. Anything it returns outside `[A-Za-z0-9]` is treated as a word break.

A custom transliterator replaces both the locale overrides and portable-ascii. To keep the overrides around your own engine, wrap it:

```php
use Pharaonic\Slugify\Transliteration\LocaleAwareTransliterator;

Slugify::useTransliterator(new LocaleAwareTransliterator(new IntlTransliterator()));
```

### Using `Slugger` Directly

`Slugger` can be built without the static entry point. In that case no default or package-wide rules are applied:

```php
use Pharaonic\Slugify\Rules\RuleSet;
use Pharaonic\Slugify\Slugger;

(new Slugger('user@host'))->toString();                          // "user-host"
(new Slugger('user@host', null, RuleSet::defaults()))->toString(); // "user-at-host"
```

## API Reference

### `Pharaonic\Slugify\Slugify`

| Method | Description | Returns |
| --- | --- | --- |
| `make(string $value, string $separator = '-', bool $ascii = false, ?string $language = null)` | Generate a slug. | `string` |
| `of(string $value, ?SlugOptions $options = null)` | Start a fluent builder that uses the current package-wide rules. | `Slugger` |
| `get(mixed $value, string $separator = '-', bool $ascii_only = false, ?string $ascii_lang = 'en')` | 2.x alias of `make()`. Accepts scalars, `Stringable` and `null`. | `string` |
| `addRule(string $search, string $replace)` | Add or override a package-wide rule. | `void` |
| `addRules(array $rules)` | Add or override several package-wide rules. | `void` |
| `rule(string $key, string $value)` | 2.x alias of `addRule()`. | `void` |
| `removeRule(string $search)` | Remove a package-wide rule, including a default. Removing a rule that does not exist does nothing. | `void` |
| `rules()` | The current package-wide rules. | `RuleSet` |
| `resetRules()` | Restore the package default rules. | `void` |
| `useTransliterator(?Transliterator $transliterator)` | Replace the package-wide transliterator; `null` restores the default. | `void` |

### `Pharaonic\Slugify\Slugger`

Every configuration method returns a new instance.

| Method | Description | Returns |
| --- | --- | --- |
| `separator(string $separator)` | Word separator. | `Slugger` |
| `lowercase(bool $lowercase = true)` | Lowercase the slug. | `Slugger` |
| `ascii(?string $language = null)` | Transliterate to ASCII. A language is a shorthand for `locale($language)->ascii()`. | `Slugger` |
| `unicode()` | Turn ASCII mode off (the default). Keeps the locale. | `Slugger` |
| `locale(?string $locale)` | Language-specific behavior; never enables ASCII. `null` removes it. | `Slugger` |
| `symbols(SymbolPolicy $policy)` | How symbols are handled. | `Slugger` |
| `emoji(EmojiPolicy $policy)` | How emoji are handled. | `Slugger` |
| `normalizeNumbers(bool $normalize = true)` | Convert Unicode digits and numerals to ASCII digits. | `Slugger` |
| `splitCamelCase(bool $split = true)` | Split camelCase words and acronyms. | `Slugger` |
| `maxLength(?int $maxLength)` | Limit the length in characters; `null` removes the limit. | `Slugger` |
| `rule(string $search, string $replace)` | Add a rule for this slug. | `Slugger` |
| `rules(array $rules)` | Add several rules for this slug. | `Slugger` |
| `withoutRules()` | Drop the default and package-wide rules. | `Slugger` |
| `transliterator(Transliterator $transliterator)` | Use a custom transliterator for this slug. | `Slugger` |
| `options()` | A copy of the current options. | `SlugOptions` |
| `toString()` / `__toString()` | Build the slug. | `string` |
| `explain()` | The text after every pipeline step, keyed by step name. | `array<string, string>` |

### `Pharaonic\Slugify\SlugOptions`

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `separator` | `string` | `'-'` | Word separator. |
| `lowercase` | `bool` | `true` | Lowercase the slug. |
| `ascii` | `bool` | `false` | Transliterate to ASCII. |
| `language` | `?string` | `null` | Locale (`de`, `tr`, `uk-UA`). Never enables ASCII. |
| `splitCamelCase` | `bool` | `true` | Split camelCase words and acronyms. |
| `maxLength` | `?int` | `null` | Maximum length in characters. |
| `symbols` | `SymbolPolicy` | `SymbolPolicy::remove()` | How symbols are handled. |
| `emoji` | `EmojiPolicy` | `EmojiPolicy::remove()` | How emoji are handled. |
| `normalizeNumbers` | `bool` | `true` | Convert Unicode digits and numerals to ASCII digits. |

### `Pharaonic\Slugify\Policies\SymbolPolicy`

| Method | Description |
| --- | --- |
| `SymbolPolicy::remove()` | Default. Symbols become word breaks. |
| `SymbolPolicy::words()` | Spell symbols out in the slug's locale, falling back to English. |
| `SymbolPolicy::custom(array $map)` | Spell out only the given `symbol => word` pairs. |

### `Pharaonic\Slugify\Policies\EmojiPolicy`

| Method | Description |
| --- | --- |
| `EmojiPolicy::remove()` | Default. Emoji sequences are removed. |
| `EmojiPolicy::custom(array $map)` | Replace the given `emoji => word` pairs, regardless of skin tone or presentation selector; other emoji are removed. |

### `Pharaonic\Slugify\Rules\RuleSet`

An immutable, ordered rule collection, returned by `Slugify::rules()`.

| Method | Description | Returns |
| --- | --- | --- |
| `RuleSet::defaults()` | The package default rules. | `RuleSet` |
| `with(string $search, string $replace)` | Copy with one rule added. | `RuleSet` |
| `merge(RuleSet\|array $rules)` | Copy with more rules merged in. | `RuleSet` |
| `without(string $search)` | Copy without a rule. | `RuleSet` |
| `has(string $search)` | Whether a rule exists. | `bool` |
| `all()` | Every rule as `search => replacement`. | `array` |
| `isEmpty()` / `count()` | Size checks. | `bool` / `int` |
| `apply(string $value, bool $caseInsensitive = false)` | Apply the rules to a string. | `string` |
| `splitForTransliteration()` | `[before, after]`: the rules applied before and after transliteration in ASCII mode. | `array` |

### Other

| Name | Description |
| --- | --- |
| `slug(mixed $value, string $separator = '-', bool $ascii_only = false, ?string $ascii_lang = 'en')` | Global helper; same as `Slugify::get()`. |
| `Contracts\Transliterator::transliterate(string $value, ?string $language = null): string` | Transliteration contract. |
| `Transliteration\LocaleAwareTransliterator` | Default transliterator: curated locale overrides, then a wrapped generic transliterator. |
| `Transliteration\PortableAsciiTransliterator` | Generic transliterator (voku/portable-ascii). |
| `Facades\Slugify` | 2.x import path; a supported alias of `Slugify`. |
| `Exceptions\InvalidArgumentException` | Thrown for invalid separators, a `maxLength` below 1, empty rule, symbol or emoji search strings, a single rule search string too large to compile, and unsupported value types. |

## Examples

### 1. Blog Post Permalinks

Generate an SEO-friendly, length-limited permalink from a post title:

```php title="app/Posts/PermalinkGenerator.php"
use Pharaonic\Slugify\Slugify;

final class PermalinkGenerator
{
    public function forTitle(string $title): string
    {
        return Slugify::of($title)->maxLength(60)->toString();
    }
}

(new PermalinkGenerator())->forTitle('10 Tips for Writing Clean PHP Code in 2026');
// "10-tips-for-writing-clean-php-code-in-2026"
```

### 2. Multilingual Site

Keep native-script slugs for Arabic content, and use ASCII slugs with the locale for German:

```php
use Pharaonic\Slugify\Slugify;

$slug = match ($locale) {
    'ar', 'fa' => Slugify::make($title),
    'de'       => Slugify::make($title, '-', true, 'de'),
    default    => Slugify::make($title, '-', true),
};

// ar: "دليل-البرمجة"     from "دليل البرمجة"
// de: "schoene-gruesse"  from "Schöne Grüße"
```

### 3. Domain-specific Rules

Register package-wide rules once at boot, then use per-slug rules for one-off cases:

- ===Service Provider

  ```php title="app/Providers/AppServiceProvider.php"
  use Pharaonic\Slugify\Slugify;

  public function boot(): void
  {
      Slugify::addRules([
          'c++' => 'cpp',
          'c#'  => 'csharp',
          '&'   => ' and ',
      ]);
  }
  ```

- ===Usage

  ```php title="app/Http/Controllers/CourseController.php"
  use Pharaonic\Slugify\Slugify;

  Slugify::make('C++ & C# Fundamentals');   // "cpp-and-csharp-fundamentals"

  Slugify::of('Price: 100%')
      ->rule('%', ' percent ')
      ->toString();                         // "price-100-percent"
  ```

### 4. File Names and Keys

Use another separator for cache keys or file names:

```php
use Pharaonic\Slugify\Slugify;

Slugify::make('Quarterly Report Q3', '_') . '.pdf';   // "quarterly_report_q3.pdf"
Slugify::make('UserProfileSettings', '.');            // "user.profile.settings"
```

### 5. Reusable Configuration

Build one configured builder and reuse it for every value:

```php
use Pharaonic\Slugify\SlugOptions;
use Pharaonic\Slugify\Slugify;

$options = new SlugOptions(separator: '_', ascii: true, maxLength: 32);

$keys = array_map(
    fn (string $name) => Slugify::of($name, $options)->toString(),
    ['Café Latte', 'Crème Brûlée', 'Pain au Chocolat']
);
// ["cafe_latte", "creme_brulee", "pain_au_chocolat"]
```

## Troubleshooting

### Cyrillic, Greek or Chinese titles are no longer romanized

Since the 8.x line, Unicode mode keeps every script. For Latin output, enable ASCII mode:

```php
Slugify::make('Привет мир', '-', true);   // "privet-mir"
```

### German umlauts become `a`/`o`/`u` instead of `ae`/`oe`/`ue`

Without a locale, transliteration uses the generic tables. Pass `de`:

```php
Slugify::make('Äpfel', '-', true, 'de');           // "aepfel"
Slugify::of('Äpfel')->locale('de')->ascii()->toString();   // "aepfel"
```

### `locale('de')` doesn't give an ASCII slug

That's by design: a locale never enables ASCII output. Add `->ascii()`.

Or add rules: `Slugify::addRules(['ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue'])`.

### My rule's replacement sticks to the next word

Replacements are literal. Add spaces around the replacement to make it a separate word:

```php
Slugify::of('500$')->rule('$', 'dollar')->toString();     // "500dollar"
Slugify::of('500$')->rule('$', ' dollar ')->toString();   // "500-dollar"
```

### A rule added at runtime doesn't apply

`Slugify::of()` captures the package-wide rules when it is called. Register rules before you create the builder, or add the rule to the builder with `->rule()`.

### Rules leak between tests

Package-wide rules are static. Call `Slugify::resetRules()` and `Slugify::useTransliterator(null)` in your test's `setUp()`/`tearDown()`.

### `InvalidArgumentException` about the separator

The separator contains a letter, number, combining mark or whitespace. Use punctuation such as `-`, `_`, `.` or `~`, or an empty string.

### Arabic or Persian digits became `0-9`

Unicode digits are normalized to ASCII by default. Keep them with `->normalizeNumbers(false)`.

### `&` disappears from my slug

Symbols are removed by default. Spell them out with `->symbols(SymbolPolicy::words())`, or add a rule such as `->rule('&', ' and ')`.

### A slug looks wrong and I can't tell why

Call `->explain()` on the builder to see the text after every step of the pipeline.

## Upgrade Guide

Slugify has one release line per PHP version, and every line has the same classes, methods and output. This page covers the `v8.6.0` line, for PHP 8.6.

### Patch Releases

Patch releases never break your code. Update with:

```bash no-line-numbers
composer update pharaonic/php-slugify
```

Slug output changes only to fix a bug, and every such change is listed in the changelog. Slugs you've already stored are never affected; only newly generated slugs can differ.

### Moving To Another PHP Version

No code changes are needed. Composer picks the line that matches your PHP version, so after upgrading PHP run `composer update pharaonic/php-slugify`.

The constraint that `composer require` writes (for example `^8.6`) already allows the newer lines. If you pinned a line with a tilde constraint such as `~8.6.0`, widen it first, or Composer stays on `8.6.x` and cannot install on the new PHP version.

### Upgrading from 2.x

The 2.x API keeps working, but some slugs come out differently. Slugs you've already stored are not affected; only newly generated slugs can change.

#### API Mapping

| 2.x | v8.6.0 | Status |
| --- | --- | --- |
| `slug($value, $sep, $ascii, $lang)` | unchanged | Supported |
| `Slugify::get(...)` | `Slugify::make(...)` | Supported alias |
| `Slugify::rule($key, $value)` | `Slugify::addRule($search, $replace)` | Supported alias |
| `use Pharaonic\Slugify\Facades\Slugify;` | `use Pharaonic\Slugify\Slugify;` | Supported alias |
| `Services\SlugifyService`, `Facades\Facade` | none | Removed (internal) |

#### Output Changes

**Unicode mode keeps every script.** 2.x romanized some scripts and kept others:

| Input | 2.x | Now |
| --- | --- | --- |
| `Привет мир` | `privet-mir` | `привет-мир` |
| `München` | `muenchen` | `münchen` |
| `你好世界` | `nihaoshijie` | `你好世界` |
| `پژوهش` | `بزوهش` | `پژوهش` |

To get Latin output, use ASCII mode: `Slugify::make($title, '-', true, 'de')`.

**Acronyms stay together.** `XMLHttpRequest` now gives `xml-http-request` (2.x: `x-mlhttp-request`).

**Fixes.** `'0'` now gives `'0'` instead of `''`. `İstanbul` gives `istanbul`. In ASCII mode, rules such as `ö` → `oe` now apply, `@` becomes `at`, and CJK and Korean text is transliterated instead of dropped.

**Rules apply in one pass.** Adding `a` → `b` and `b` → `c` now turns `ab` into `bc` (2.x: `cc`).

:::info Laravel Sluggable
`pharaonic/laravel-sluggable` calls `slug($value, $separator, $ascii_only, $ascii_lang)`, and that signature is unchanged. If your app relied on the 2.x romanization, set `ascii_only` to `true` in its config.
:::

### Changelog

Every release is listed in the [changelog](https://github.com/Pharaonic/php-slugify/blob/8.6.x/CHANGELOG.md) and on the [GitHub releases](https://github.com/Pharaonic/php-slugify/releases) page.
