Skip to content

Instantly share code, notes, and snippets.

@ReeMii
Created September 26, 2013 09:25
Show Gist options
  • Save ReeMii/6711869 to your computer and use it in GitHub Desktop.
Save ReeMii/6711869 to your computer and use it in GitHub Desktop.
str2url
function str2url($string, $slug = '-', $extra = null)
{
return strtolower(trim(preg_replace('~[^0-9a-z' . preg_quote($extra, '~') . ']+~i', $slug, unaccent($string)), $slug));
}
function unaccent($string) // normalizes (romanization) accented chars
{
if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false) {
$string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8');
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment