PHPackages                             javiereguiluz/easyslugger - 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. javiereguiluz/easyslugger

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

javiereguiluz/easyslugger
=========================

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

v1.0.0(11y ago)791.0M↓24.7%4[1 issues](https://github.com/javiereguiluz/EasySlugger/issues)[1 PRs](https://github.com/javiereguiluz/EasySlugger/pulls)5MITPHPPHP &gt;=5.3.3

Since Apr 12Pushed 8y ago3 watchersCompare

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

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

EasySlugger
===========

[](#easyslugger)

[![Build Status](https://camo.githubusercontent.com/b55bbc888d56df6f2442bb9d0fd3e9a50f15ab42a5b115dbf1c4aad70e165c41/68747470733a2f2f7472617669732d63692e6f72672f6a6176696572656775696c757a2f45617379536c75676765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/javiereguiluz/EasySlugger)[![SensioLabsInsight](https://camo.githubusercontent.com/7799988fe2d319b7738a68e51f4c704f30e588b4597c33f499001e2c38399eed/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f34336264353338632d303539322d346663662d386231652d6233663961366536373538352f6d696e692e706e67)](https://insight.sensiolabs.com/projects/43bd538c-0592-4fcf-8b1e-b3f9a6e67585)

**EasySlugger** is a fast PHP library to generate slugs, which allow to safely include any string as part of an URL. Slugs are commonly used for CMS, blogs and other content-related platforms.

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

[](#installation)

Add this library as a dependency of your project using [Composer](https://getcomposer.org/):

```
$ cd your-project/
$ composer require javiereguiluz/easyslugger
```

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

[](#generating-slugs)

Most slugger libraries include a lot of settings to configure how the slugs are generated. **EasySlugger** uses a different approach to provide both a great performance and 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`, which allows you to safely switch from one slugger to another in your projects.

Generating basic slugs
----------------------

[](#generating-basic-slugs)

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

```
use EasySlugger\Slugger;

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

You can also instantiate the `Slugger` class to use it non-statically:

```
// PHP 5.4 or lower
use EasySlugger\Slugger;

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

// PHP 5.5 or higher
$slugger = (new \EasySlugger\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()` method, which appends a random suffix to the slug:

```
use EasySlugger\Slugger;

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

Unique slugs are 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 non-latin alphabets
----------------------------------------

[](#generating-slugs-for-non-latin-alphabets)

If the strings contain characters belonging to non-latin alphabets 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 EasySlugger\Utf8Slugger;

$slug = Utf8Slugger::slugify('日本語');  // slug = ri-ben-yu
$slug = Utf8Slugger::slugify('العَرَبِيةُ‎‎');    // slug = alrbyt
$slug = Utf8Slugger::slugify('עברית');  // slug = bryt
```

`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 EasySlugger\SeoSlugger;

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

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

$slug = SeoSlugger::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 available 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 EasySlugger\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 EasySlugger\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)

This 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 easyslugger/
$ composer install
$ phpunit
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity51

Moderate usage in the ecosystem

Community17

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

4054d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/93dbdd4a2471e93a797afb9253151f7ead2b0f57d205d307d5ba94ab3d885da9?d=identicon)[javier.eguiluz](/maintainers/javier.eguiluz)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/javiereguiluz-easyslugger/health.svg)

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

###  Alternatives

[stechstudio/laravel-raw-sessions

A raw PHP session handler for Laravel

2297.1k](/packages/stechstudio-laravel-raw-sessions)[verbb/gift-voucher

Sell and redeem digital gift vouchers for Craft Commerce.

1322.5k1](/packages/verbb-gift-voucher)[phpexperts/workday-planner

Given a date range, this will give you all of the workdays for that country.

251.5k](/packages/phpexperts-workday-planner)[tombroucke/sage-bootstrap-components

Bootstrap 4 components for Sage

113.1k1](/packages/tombroucke-sage-bootstrap-components)

PHPackages © 2026

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