Skip to content

Instantly share code, notes, and snippets.

@victorknust
Forked from astrocosa/slug.php
Created October 26, 2016 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorknust/d95e0ce1f5769e56357c80da93680d7e to your computer and use it in GitHub Desktop.
Save victorknust/d95e0ce1f5769e56357c80da93680d7e 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