PHPackages                             rjds/php-slugify - 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. rjds/php-slugify

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

rjds/php-slugify
================

A PHP library to convert a string into a clean URL-safe lowercase string.

v2.2.0(3mo ago)00MITPHPPHP ^8.1CI passing

Since Mar 12Pushed 2mo agoCompare

[ Source](https://github.com/RubenJ01/php-slugify)[ Packagist](https://packagist.org/packages/rjds/php-slugify)[ RSS](/packages/rjds-php-slugify/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (4)Dependencies (5)Versions (11)Used By (0)

PHP Slugify
===========

[](#php-slugify)

[![Version](https://camo.githubusercontent.com/4467a76c5b9cd507285b60f48d6cbfb2a80033e10ab85550650ca416c8019a64/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f527562656e4a30312f7068702d736c75676966793f6c6162656c3d76657273696f6e)](https://camo.githubusercontent.com/4467a76c5b9cd507285b60f48d6cbfb2a80033e10ab85550650ca416c8019a64/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f527562656e4a30312f7068702d736c75676966793f6c6162656c3d76657273696f6e)[![codecov](https://camo.githubusercontent.com/c69243ec5bbdff82cd222590686d584d709e8f9963952a469d950e2ea67098ac/68747470733a2f2f636f6465636f762e696f2f6769746875622f527562656e4a30312f7068702d736c75676966792f67726170682f62616467652e737667)](https://codecov.io/github/RubenJ01/php-slugify)[![status-badge](https://camo.githubusercontent.com/9631711260172d8f728100350f47f40af53eccdac22fb6e5fd8015ecf4a569c3/68747470733a2f2f63692e727562656e6a616b6f622e636f6d2f6170692f6261646765732f312f7374617475732e737667)](https://ci.rubenjakob.com/repos/1)[![License](https://camo.githubusercontent.com/770dab7285fbe2a23a0d3c283eb516e503261e260244be482ff9600decec856b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f527562656e4a30312f7068702d736c7567696679)](https://camo.githubusercontent.com/770dab7285fbe2a23a0d3c283eb516e503261e260244be482ff9600decec856b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f527562656e4a30312f7068702d736c7567696679)

A PHP library to convert a string into a clean URL-safe lowercase string.

Requirements
------------

[](#requirements)

RequirementVersionPHP8.1+ext-intl\*Installation
------------

[](#installation)

Install from Packagist with Composer:

```
composer require rjds/php-slugify
```

Usage
-----

[](#usage)

Getting started with php-slugify is simple.

### Basic Example

[](#basic-example)

```
use Rjds\PhpSlugify\SluggerFactory;

$slugger = SluggerFactory::create();

// Outputs: hello-world-2026
echo $slugger->slugify('Hello World 2026!');
```

### Customizing the Divider

[](#customizing-the-divider)

You can change the default hyphen to any other character:

```
// Outputs: hello_world_2026
echo $slugger->slugify('Hello World 2026', '_');
```

### Custom Character Mapping

[](#custom-character-mapping)

You can pass an associative array of custom character replacements via the `mappings` parameter. Mappings are applied before transliteration, enabling domain-specific replacements:

```
// Outputs: tom-and-jerry
echo $slugger->slugify('Tom & Jerry', mappings: ['&' => 'and']);

// Outputs: contact-at-example-dot-com
echo $slugger->slugify('contact@example.com', mappings: ['@' => ' at ', '.' => ' dot ']);

// Combine with a custom divider
// Outputs: price_10_eur
echo $slugger->slugify('Price 10€', divider: '_', mappings: ['€' => ' eur']);
```

### Language-Aware Transliteration

[](#language-aware-transliteration)

By default, the slugger uses generic Unicode-to-ASCII transliteration. For languages with specific conventions, pass a locale to `SluggerFactory::create()`:

```
// German: ü → ue, ö → oe, ä → ae, ß → ss
$slugger = SluggerFactory::create('de');

// Outputs: ueber-die-bruecke
echo $slugger->slugify('Über die Brücke');

// Outputs: strasse
echo $slugger->slugify('Straße');
```

```
// Turkish: ı → i, İ → I, ş → s, ç → c, ğ → g
$slugger = SluggerFactory::create('tr');

// Outputs: istanbul
echo $slugger->slugify('İstanbul');
```

Supported locales: `de` (German), `tr` (Turkish).

User-provided `mappings` override locale mappings when both define the same character:

```
$slugger = SluggerFactory::create('de');

// Outputs: u-boot (user mapping Ü → U overrides locale Ü → Ue)
echo $slugger->slugify('Ü-Boot', mappings: ['Ü' => 'U']);
```

### Max Length / Truncation

[](#max-length--truncation)

You can limit the slug length with the `maxLength` parameter. The slug is truncated on a word boundary so words are never cut in half:

```
// Outputs: the-quick (truncated at word boundary, not "the-quick-bro")
echo $slugger->slugify('The Quick Brown Fox', maxLength: 14);

// Outputs: hello-world (no truncation needed)
echo $slugger->slugify('Hello World', maxLength: 50);

// Combine with a custom divider
// Outputs: hello_world
echo $slugger->slugify('Hello World 2026', '_', maxLength: 15);
```

### Empty Input Handling

[](#empty-input-handling)

By default, an empty string input returns an empty string. You can customize this with the `emptyValue` parameter:

```
// Outputs: (empty string)
echo $slugger->slugify('');

// Outputs: n-a
echo $slugger->slugify('', emptyValue: 'n-a');
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance83

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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

Every ~4 days

Total

3

Last Release

94d ago

Major Versions

1.0.0 → v2.1.02026-03-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/f14e57627c79da2510555b59c25b7becccb6363cfeb516bb115bb5a1fb3c215c?d=identicon)[RubenJ01](/maintainers/RubenJ01)

---

Top Contributors

[![RubenJ01](https://avatars.githubusercontent.com/u/45236226?v=4)](https://github.com/RubenJ01 "RubenJ01 (40 commits)")

---

Tags

composer-packagephpphp-libraryseoslugslugifytransliterationunicodeurl

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rjds-php-slugify/health.svg)

```
[![Health](https://phpackages.com/badges/rjds-php-slugify/health.svg)](https://phpackages.com/packages/rjds-php-slugify)
```

###  Alternatives

[kylewm/brevity

A small utility to count characters and shorten posts to tweet-length.

12293.5k5](/packages/kylewm-brevity)[surfsidemedia/shoppingcart

Laravel Shoppingcart

1713.6k](/packages/surfsidemedia-shoppingcart)

PHPackages © 2026

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