Skip to content

Instantly share code, notes, and snippets.

@diogoca
Created September 24, 2013 21:02
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 diogoca/6691191 to your computer and use it in GitHub Desktop.
Save diogoca/6691191 to your computer and use it in GitHub Desktop.
Php Slug Function
public function slug($name)
{
$name = mb_strtolower($name, 'UTF-8');
$pattern = array(
'/[âãàáä]/u',
'/[êèéë]/u',
'/[îíìï]/u',
'/[ôõòóö]/u',
'/[ûúùü]/u',
'/[ç]/u',
'/^[^a-z0-9]+/u',
'/[^a-z0-9]+$/u',
'/[^a-z0-9]+/u',
);
$replacement = array(
'a',
'e',
'i',
'o',
'u',
'c',
'',
'',
'-'
);
return preg_replace($pattern, $replacement, $name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment