breda/slugger

There is no license information available for the latest version (1.0.1) of this package.

This library provides a utility class to make slugs out of strings.

1.0.1 2019-03-27 10:48 UTC

This package is auto-updated.

Last update: 2024-06-11 14:54:47 UTC


README

Slugger is a simple PHP utility class to make slugs out of strings, that can handle special Arabic/French characters.

Build Status

While working at Kreo,

I needed a library that can generate slugs from strings with some special characters, like French accented characters as well as Arabic Shadda and special Arabic characters (like the Arabic comma ،).

This might not be a complete slugger but this what worked for me at the time, so I thought I'd share it. Any suggestions and feedback are most welcome :-)

Example usage

use BReda\Slugger\Slugger;

// Normal call
$slugger = new Slugger('-', [
    // Presets here, remove/add what's needed, 
    // but at least the basic preset should be present.
    new \BReda\Slugger\Presets\BasicPreset,
    new \BReda\Slugger\Presets\ArabicPreset,
]);

// Load a new preset
$slugger->loadPreset(new \BReda\Slugger\Presets\FrenchPreset);

// Make the slug
$slugged = $slugger->make("This should be slugged");

// Statically
// When using staticMake, all available presets will be loaded.
$slugged = Slugger::staticMake("This should be slugged too", "-");

I wrote this utility class to be compatible with Eloquent Sluggable which I was using at the time, with Laravel PHP Framework. But it can be used anywhere of course.