Skip to content

Instantly share code, notes, and snippets.

@astrocosa
Created January 7, 2012 03:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save astrocosa/1573646 to your computer and use it in GitHub Desktop.
Save astrocosa/1573646 to your computer and use it in GitHub Desktop.
Function slug
<?php
function slug($str, $cat=false) {
$ene = ($cat === true) ? 'ny' : 'n';
$str = (function_exists('mb_strtolower')) ? mb_strtolower($str, 'UTF-8') : strtolower($str);
$str = preg_replace('(à|á|â|ã|ä|å)', 'a', $str);
$str = preg_replace('(è|é|ê|ë)', 'e', $str);
$str = preg_replace('(ì|í|î|ï)', 'i', $str);
$str = preg_replace('(ò|ó|ô|õ|ö|ø|ō)', 'o', $str);
$str = preg_replace('(ù|ú|û|ü|ū)', 'u', $str);
$str = preg_replace('(ñ)', $ene, $str);
$str = str_replace(array('\\','/','.',',',':'), ' ', $str);
$str = preg_replace('([^ a-z0-9_])', '', $str);
$str = trim($str);
$str = preg_replace('/\s+/','-', $str);
return $str;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment