PHP code example of treehouselabs / slugifier

1. Go to this page and download the library: Download treehouselabs/slugifier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

treehouselabs / slugifier example snippets


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

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

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

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