1. Go to this page and download the library: Download cocur/slugify 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/ */
cocur / slugify example snippets
use Cocur\Slugify\Slugify;
$slugify = new Slugify();
echo $slugify->slugify("Hello World!"); // hello-world
public function __construct(\Cocur\Slugify\SlugifyInterface $slugify)
use Cocur\Slugify\Bridge\Twig\SlugifyExtension;
use Cocur\Slugify\Slugify;
$twig = new Twig_Environment($loader);
$twig->addExtension(new SlugifyExtension(Slugify::create()));
// laravel/app/config/packages/rcrowe/twigbridge/config.php
'extensions' => array(
//...
function () {
return new \Cocur\Slugify\Bridge\Twig\SlugifyExtension(\Cocur\Slugify\Slugify::create());
},
),
use Cocur\Slugify\Slugify;
$mustache = new Mustache_Engine([
// ...
"helpers" => [
"slugify" => function ($string, $separator = null) {
return Slugify::create()->slugify($string, $separator);
},
],
]);
class MyPresenter extends \Nette\Application\UI\Presenter
{
/** @var \Cocur\Slugify\SlugifyInterface @inject */
public $slugify;
public function renderDefault()
{
$this->template->hello = $this->slugify->slugify("Hällo Wörld");
}
}
use Cocur\Slugify\Bridge\Latte\SlugifyHelper;
use Cocur\Slugify\Slugify;
use Latte;
$latte = new Latte\Engine();
$latte->addFilter("slugify", [new SlugifyHelper(Slugify::create()), "slugify"]);
$container["view"] = function ($c) {
$settings = $c->get("settings");
$view = new \Slim\Views\Twig(
$settings["view"]["template_path"],
$settings["view"]["twig"]
);
$view->addExtension(
new Slim\Views\TwigExtension(
$c->get("router"),
$c->get("request")->getUri()
)
);
$view->addExtension(
new Cocur\Slugify\Bridge\Twig\SlugifyExtension(
Cocur\Slugify\Slugify::create()
)
);
return $view;
};
use Cocur\Slugify;
use League\Container;
/* @var Container\ContainerInterface $container */
$container->addServiceProvider(
new Slugify\Bridge\League\SlugifyServiceProvider()
);
/* @var Slugify\Slugify $slugify */
$slugify = $container->get(Slugify\SlugifyInterface::class);