PHPackages                             easybook/slugger - 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. easybook/slugger

Abandoned → [javiereguiluz/slugger](/?search=javiereguiluz%2Fslugger)Library[Utility &amp; Helpers](/categories/utility)

easybook/slugger
================

A fast and easy to use slugger with full UTF-8 support.

1.0.0(12y ago)2153.0k↓40.5%41MITPHPPHP &gt;=5.3.3

Since Apr 8Pushed 12y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (1)

Slugger
=======

[](#slugger)

**[slugger](http://github.com/easybook/slugger)** is a fast PHP library to generate *slugs*, which allows to safely include any string as part of an URL. Slugs are commonly used for CMS, blogs and other content-related platforms.

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

[](#installation)

The easiest way to install **slugger** is to add this library as a dependency of your project using [Composer](https://getcomposer.org/):

```
$ cd your-project/
$ composer require easybook/slugger 1.*

```

If you prefer, add the new dependency by hand to your `composer.json` file and then, execute the `composer update` command to update your dependencies:

```
{
    "name"        : "...",
    "description" : "...",
    "require": {
        "php"              : ">=5.3.3",
        "easybook/slugger" : "1.0.*"
    }
}
```

Generating slugs
----------------

[](#generating-slugs)

Most slugger libraries include a lot of settings to configure how the slugs are generated. **slugger** uses a different approach to offer both a great performance and enough flexibility: it includes four different slugger classes!

- `Slugger`, fast slugs suited for most European languages.
- `Utf8Slugger`, UTF-8-compliant slugger suitable for any alphabet (including japanese, arabic and hebrew languages). It requires PHP 5.4.0 or higher.
- `SeoSlugger`, advanced slugger that augments the strings before turning them into slugs. For instance, the string `The product #3 costs $9.99` is turned into `the-product-number-3-costs-9-dollars-99-cents`.
- `SeoUtf8Slugger`, combines the `Utf8Slugger` and the `SeoSlugger` to augment and slugify any UTF-8 string.

All sluggers implement the `SluggerInterface` interface, which allows you to safely switch in your projects from one slugger to another.

### Generating basic slugs

[](#generating-basic-slugs)

The easiest way to generate slugs is to use the `slugify()` method of the `Slugger` class:

```
use Easybook\Slugger;

$slugger = new Slugger();
$slug = $slugger->slugify('Lorem Ipsum'); // slug = lorem-ipsum
```

If you use PHP 5.5.0 or higher, you can generate slugs with a single line of code:

```
$slugger = (new \Easybook\Slugger())->slugify('Lorem Ipsum');
```

### Generating unique slugs

[](#generating-unique-slugs)

If you need to ensure the uniqueness of the slugs generated during the execution of your application, use the `uniqueSlugify()`, which appends a random suffix to the slug:

```
use Easybook\Slugger;

$slugger = new Slugger();
$slug = $slugger->uniqueSlugify('Lorem Ipsum'); // slug = lorem-ipsum-a2b342f
```

Keep in mind that the generation of the unique slugs is non-deterministic, meaning that the appended suffix is random and it will change in each application execution, even when using the same input string.

If you want to append an autoincremental numeric suffix to the slugs, you'll need to develop your own custom solution.

### Generating slugs for complex languages

[](#generating-slugs-for-complex-languages)

If the strings contain characters belonging to complex languages such as Arabic, Hebrew and Japanese, you should use the `Utf8Slugger` class. This slugger requires PHP 5.4.0 or higher because it uses the built-in PHP transliterator:

```
use Easybook\Utf8Slugger;

$slugger = new Utf8lugger();
$slug = $slugger->slugify('日一国会'); // slug = ri-yi-guo-hui
$slug = $slugger->slugify('ضطظع');    // slug = fqklmnhwyy
$slug = $slugger->slugify('נסעףפ');   // slug = wwwyyy
```

`Utf8Slugger` also defines the `uniqueSlugify()` to generate unique slugs.

### Generating SEO slugs

[](#generating-seo-slugs)

The `SeoSlugger` (and the related `SeoUtf8Slugger`) augments the strings before turning them into slugs. The conversions are related to numbers, currencies, email addresses and other common symbols:

```
use Easybook\SeoSlugger;

$slugger = new SeoSlugger();

$slug = $slugger->slugify('The price is $5.99');
// slug = the-price-is-5-dollars-99-cents

$slug = $slugger->slugify('Use lorem@ipsum.com to get a 10% discount');
// slug = use-lorem-at-ipsum-dot-com-to-get-a-10-percent-discount

$slug = $slugger->slugify('Gravity = 9.81 m/s2');
// slug = gravity-equals-9-dot-81-m-s2
```

`SeoSlugger` and `SeoUtf8Slugger` also define the `uniqueSlugify()` to generate unique slugs.

Configuration options
---------------------

[](#configuration-options)

The only configuration option defined by **slugger** is the `separator`character (or string) used to separate each of the slug parts. First, you can set this parameter globally using the class constructor:

```
use Easybook\Slugger;

$slugger = new Slugger();
$slug = $slugger->slugify('Lorem Ipsum'); // slug = lorem-ipsum

$slugger = new Slugger('_');
$slug = $slugger->slugify('Lorem Ipsum'); // slug = lorem_ipsum

$slugger = new Slugger('');
$slug = $slugger->slugify('Lorem Ipsum'); // slug = loremipsum
```

You can also set this parameter as the second optional argument of the `slugify()` and `uniqueSlugify()` methods. This parameter always overrides any global parameter set by the class:

```
use Easybook\Slugger;

$slugger = new Slugger();
$slug = $slugger->slugify('Lorem Ipsum', '_'); // slug = lorem_ipsum
$slug = $slugger->slugify('Lorem Ipsum', '');  // slug = loremipsum

$slugger = new Slugger('+');
$slug = $slugger->slugify('Lorem Ipsum', '_'); // slug = lorem_ipsum
```

License
-------

[](#license)

**slugger** library is licensed under the [MIT license](LICENSE.md).

Tests
-----

[](#tests)

The library is fully unit tested. If you have [PHPUnit](http://phpunit.de/)installed, execute `phpunit` command to run the complete test suite:

```
$ cd slugger/
$ phpunit
PHPUnit 3.7.32 by Sebastian Bergmann.

Configuration read from slugger/phpunit.xml.dist

.........................................................  63 / 103 ( 61%)
........................................

Time: 2.12 seconds, Memory: 2.00Mb

OK (103 tests, 499 assertions)

```

Code Quality Assurance
----------------------

[](#code-quality-assurance)

SensioLabs InsightTravis CIScrutinizer CI[![SensioLabsInsight](https://camo.githubusercontent.com/b90f05ffd6d47b04e7b261f1f6d93e7336a007d4ba80cb05670075ce47292e4b/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65366261313335382d656137362d346135312d616134342d3939363564623937643061642f6269672e706e67)](https://insight.sensiolabs.com/projects/e6ba1358-ea76-4a51-aa44-9965db97d0ad)[![Travis CI status](https://camo.githubusercontent.com/ce93675aeb27d96af4620b781609fa0c76e3a3dc2f63147ac2f2024af23f798c/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f65617379626f6f6b2f736c75676765722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/easybook/slugger)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/3d0ebdffa8e547ebb1169df5b82c7343c8a41fab67f40e73492be04055c7303e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f65617379626f6f6b2f736c75676765722f6261646765732f7175616c6974792d73636f72652e706e673f733d38346661613761653333633532356636646565653266393363666164353962633633623731383965)](https://scrutinizer-ci.com/g/easybook/slugger/)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

4423d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cfca9db1e00cf5b576da9252ab3a6c0e779880f0e795db3259e30b31975f1e3?d=identicon)[javiereguiluz](/maintainers/javiereguiluz)

---

Top Contributors

[![javiereguiluz](https://avatars.githubusercontent.com/u/73419?v=4)](https://github.com/javiereguiluz "javiereguiluz (6 commits)")

### Embed Badge

![Health badge](/badges/easybook-slugger/health.svg)

```
[![Health](https://phpackages.com/badges/easybook-slugger/health.svg)](https://phpackages.com/packages/easybook-slugger)
```

PHPackages © 2026

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