2017 © Pedro Peláez
 

library slugifier

Slugifier

image

treehouselabs/slugifier

Slugifier

  • Monday, September 15, 2014
  • by fieg
  • Repository
  • 9 Watchers
  • 6 Stars
  • 75,192 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 6 % Grown

The README.md

Slugifier

Simple, extensible library that converts a string to a slug., (*1)

Another one?

Yep, sorry. We think this one is pretty good though. Check out the features to see if it's good for you, too., (*2)

Features

  • Lightweight: no dependencies, other than the mbstring and iconv extensions, which are almost always present.
  • Easy to use: (new Slugifier())->slugify('Look Ma, no hands!'); // look-ma-no-hands
  • Handles special characters, all kinds of quotes, transliteration, HTML entities, and more. All out of the box.
  • Extensible: add your custom translations
  • PSR-4 compatible and written using PRS-2 coding guidelines Scrutinizer Code Quality
  • Well-tested Build Status

Usage

$slugifier = new Slugifier();
$slugifier->slugify('Look má, I\'m a „slug”'); // look-ma-im-a-slug

Use a different delimiter:, (*3)

$slugifier = new Slugifier();
$slugifier->slugify('Foo, bar & baz', '_'); // foo_bar_baz

Add special translations:, (*4)

```php $slugifier = new Slugifier(); $slugifier->addTranslator(new EnglishTranslator()); $slugifier->slugify('Cow & chicken'); // cow-and-chicken, (*5)


Or write your own: ```php class CowTranslator implements TranslatorInterface { public function translate($str) { return str_ireplace('cow', 'supercow', $str); } } $slugifier = new Slugifier(); $slugifier->addTranslator(new CowTranslator()); $slugifier->slugify('Cow to the rescue'); // supercow-to-the-rescue

Changing the default behaviour

By default, special characters, quotes, HTML entities and more are converted. You can disable this behaviour by passing false to the constructor. This way you can start from scratch and add your own translators. The iconv transliteration is still performed though as we want to convert to ascii while preserving as much of the original data as possible., (*6)

The Versions

15/09 2014

dev-master

9999999-dev

Slugifier

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • ext-iconv *
  • php >=5.4

 

The Development Requires

url slug slugify slugifier urlize

15/09 2014

v1.0.1

1.0.1.0

Slugifier

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • ext-iconv *
  • php >=5.4

 

The Development Requires

url slug slugify slugifier urlize

24/07 2014

v1.0.0

1.0.0.0

Slugifier

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • ext-iconv *
  • php >=5.4

 

The Development Requires

url slug slugify slugifier urlize