Skip to content

Instantly share code, notes, and snippets.

@OO00O0O
Last active May 18, 2016 12:35
Show Gist options
  • Save OO00O0O/a5de760c297a488c6152 to your computer and use it in GitHub Desktop.
Save OO00O0O/a5de760c297a488c6152 to your computer and use it in GitHub Desktop.
Multi lang slug generator with simple translit
<?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