Skip to content

Instantly share code, notes, and snippets.

@jonathantorres
Last active December 22, 2015 19:19
Show Gist options
  • Save jonathantorres/6518925 to your computer and use it in GitHub Desktop.
Save jonathantorres/6518925 to your computer and use it in GitHub Desktop.
// v1
private function _short_name($str, $replace = array(), $delimiter = '-')
{
if (!empty($replace)) {
$str = str_replace((array) $replace, ' ', trim($str));
}
$str = str_replace(array('ç', 'Ç'), 'c', $str);
$clean = iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', trim($str));
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
}
// v2
private function _short_name($str, $replace = array(), $delimiter = '-')
{
if (!empty($replace)) {
$str = str_replace((array) $replace, ' ', trim($str));
}
$str = str_replace(array('ç', 'Ç'), 'c', $str);
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', trim($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