PHPackages                             vnsdks/slug-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vnsdks/slug-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vnsdks/slug-generator
=====================

Slug Generator

v1.0.1(8y ago)014.1k↓33.3%1MITPHPPHP ^7.0

Since Aug 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/vnsdks/slug-generator)[ Packagist](https://packagist.org/packages/vnsdks/slug-generator)[ RSS](/packages/vnsdks-slug-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

This library provides methods to generate slugs for URLs, filenames or any other target that has a limited character set. It’s based on PHPs Transliterator class which uses the data of the [CLDR](http://cldr.unicode.org/ "Unicode Common Locale Data Repository")to transform characters between different scripts (e.g. Cyrillic to Latin) or types (e.g. upper- to lower-case or from special characters to ASCII).

Usage
-----

[](#usage)

```
$generator = new SlugGenerator;

$generator->generate('Hello Wörld!');  // Output: hello-world
$generator->generate('Καλημέρα');      // Output: kalemera
$generator->generate('фильм');         // Output: film
$generator->generate('富士山');         // Output: fu-shi-shan
$generator->generate('國語');           // Output: guo-yu

// Different valid character set, a specified locale and a delimiter
$generator = new SlugGenerator((new SlugOptions)
    ->setValidChars('a-zA-Z0-9')
    ->setLocale('de')
    ->setDelimiter('_')
);
$generator->generate('Äpfel und Bäume');  // Aepfel_und_Baeume
```

Installation
------------

[](#installation)

To install the library use [Composer](https://getcomposer.org/) or download the source files from GitHub.

```
composer require vnsdks/slug-generator
```

Why create another slug library, aren’t there enough already?
-------------------------------------------------------------

[](#why-create-another-slug-library-arent-there-enough-already)

There are many code snippets and some good libraries out there that create slugs, but I didn’t find anything that met my requirements. Options are often very limited which makes it hard to customize for different use cases. Some libs carry large rulesets with them that try to convert characters to ASCII, no one uses Unicode’s [CLDR](http://cldr.unicode.org/ "Unicode Common Locale Data Repository")which is the standard for transliteration rules and many other transforms. But most importantly no library was able to do the “correct” conversions, like “Ö-Äpfel” to “OE-Aepfel” for German or “İNATÇI” to “inatçı” for Turkish.

Options
-------

[](#options)

All options can be set for the generator object itself `new SlugGenerator($options)`or overwritten when calling `generate($text, $options)`. Options can by passed as array or as `SlugOptions` object.

### `delimiter`, default `"-"`

[](#delimiter-default--)

The delimiter can be any string, it is used to separate words. It gets stripped from the beginning and the end of the slug.

```
$generator->generate('Hello World!');                         // Result: hello-world
$generator->generate('Hello World!', ['delimiter' => '_']);   // Result: hello_world
$generator->generate('Hello World!', ['delimiter' => '%20']); // Result: hello%20world
```

### `validChars`, default `"a-z0-9"`

[](#validchars-default-a-z0-9)

Valid characters that are allowed in the slug. The [range syntax](http://www.regular-expressions.info/charclass.html) is the same as in character classes of regular expressions. For example `abc`, `a-z0-9äöüß` or `\p{Ll}\-_`.

```
$generator->generate('Hello World!');                             // Result: hello-world
$generator->generate('Hello World!', ['validChars' => 'A-Z']);    // Result: HELLO-WORLD
$generator->generate('Hello World!', ['validChars' => 'A-Za-z']); // Result: Hello-World
```

### `ignoreChars`, default `"\p{Mn}\p{Lm}"`

[](#ignorechars-default-pmnplm)

Characters that should be completely removed and not replaced with a delimiter. It uses the same syntax as the `validChars` option.

```
$generator->generate("don't remove");                         // Result: don-t-remove
$generator->generate("don't remove", ['ignoreChars' => "'"]); // Result: dont-remove
```

### `locale`, default `""`

[](#locale-default-)

The locale that should be used for the Unicode transformations.

```
$generator->generate('Hello Wörld!');                        // Result: hello-world
$generator->generate('Hello Wörld!', ['locale' => 'de']);    // Result: hello-woerld
$generator->generate('Hello Wörld!', ['locale' => 'en_US']); // Result: hello-world
```

### `transforms`, default `Upper, Lower, Latn, ASCII, Upper, Lower`

[](#transforms-default-upper-lower-latn-ascii-upper-lower)

Transform rules or rule sets that are used by the `Transliterator`to convert invalid characters to valid ones. [Rules](http://userguide.icu-project.org/transforms/general) are for example `Lower` or `ASCII`, [rule sets](http://userguide.icu-project.org/transforms/general/rules) look like `a > b; c > d;`.

```
$generator->generate('Damn 💩!!');                                           // Result: damn
$generator->generate('Damn 💩!!', ['transforms' => ['💩 > Ice-Cream']]);     // Result: amn-ce-ream
$generator->generate('Damn 💩!!', ['postTransforms' => ['💩 > Ice-Cream']]); // Result: damn-ce-ream
$generator->generate('Damn 💩!!', ['preTransforms' => ['💩 > Ice-Cream']]);  // Result: damn-ice-cream
```

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Total

4

Last Release

3089d ago

PHP version history (2 changes)v1.0.0-alpha1PHP ^7.1

v1.0.1PHP ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5856920?v=4)[vnsdks](/maintainers/vnsdks)[@vnsdks](https://github.com/vnsdks)

---

Top Contributors

[![ausi](https://avatars.githubusercontent.com/u/367169?v=4)](https://github.com/ausi "ausi (20 commits)")[![abdusco](https://avatars.githubusercontent.com/u/3243482?v=4)](https://github.com/abdusco "abdusco (1 commits)")[![fiedsch](https://avatars.githubusercontent.com/u/5047601?v=4)](https://github.com/fiedsch "fiedsch (1 commits)")

---

Tags

slugslugifyunicodecldrasciitransliterationslug-generatorpretty-url

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/vnsdks-slug-generator/health.svg)

```
[![Health](https://phpackages.com/badges/vnsdks-slug-generator/health.svg)](https://phpackages.com/packages/vnsdks-slug-generator)
```

###  Alternatives

[ausi/slug-generator

Slug Generator

8002.2M22](/packages/ausi-slug-generator)[jbroadway/urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

6737.4M62](/packages/jbroadway-urlify)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[voku/portable-ascii

Portable ASCII library - performance optimized (ascii) string functions for php.

574401.5M117](/packages/voku-portable-ascii)[voku/urlify

PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.

254.1M7](/packages/voku-urlify)[keyvanakbary/slugifier

A full-featured, simple, clean and pure functional implementation for creating slugs

68187.9k4](/packages/keyvanakbary-slugifier)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
