Skip to content

Instantly share code, notes, and snippets.

@gregory-yet
Created November 10, 2017 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregory-yet/2a9058d96d023fef9bbd53231f9fba08 to your computer and use it in GitHub Desktop.
Save gregory-yet/2a9058d96d023fef9bbd53231f9fba08 to your computer and use it in GitHub Desktop.
Include this file in SMARTY_DIR/libs/plugins with this name : modifier.slugify.php
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Generate a slug
* Type: modifier<br>
* Name: slugify<br>
* Purpose: Sanitize a string for URL usage
* {@internal {$string|slugify}}
*
* @param string $string string vers slug
*
* @return string slug
* @author Grégory GERARD
*/
function smarty_modifier_slugify($string) {
$string = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $string);
$string = preg_replace('/[-\s]+/', '-', $string);
return trim($string, '-');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment