breda / slugger
This library provides a utility class to make slugs out of strings.
Requires
- php: ^7.2
- ext-mbstring: *
Requires (Dev)
- mockery/mockery: ^1.2
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-11-11 15:40:37 UTC
README
Slugger is a simple PHP utility class to make slugs out of strings, that can handle special Arabic/French characters.
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.