Last active
May 18, 2016 12:35
-
-
Save OO00O0O/a5de760c297a488c6152 to your computer and use it in GitHub Desktop.
Multi lang slug generator with simple translit
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 | |
public static function slug($str, $replace = [], $delimiter = '-') | |
{ | |
if(count($replace)) { | |
$str = str_replace($replace, ' ', $str); | |
} | |
setlocale(LC_CTYPE, 'en_US.UTF8'); | |
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str); | |
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); | |
$clean = strtolower(trim($clean, '-')); | |
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); | |
return $clean; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment