Created
November 10, 2017 08:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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