Skip to content

Instantly share code, notes, and snippets.

@samatsav
Created October 21, 2013 13:31
Show Gist options
  • Save samatsav/7083921 to your computer and use it in GitHub Desktop.
Save samatsav/7083921 to your computer and use it in GitHub Desktop.
Inlocuieste diacriticele cu caractere compatibile ASCII. (@@todo: inainte de a folosii functia, a se scoate din $map conversiile in plus)
function ro_slugs($cuvant) {
$slug = trim(strtolower(stripslashes($cuvant)));
$map = array(
'/à|á|å|â|ă|â|Â|Ă|ă/i' => 'a',
'/è|é|ê|ẽ|ë/i' => 'e',
'/ì|í|î|î|Î|Î/i' => 'i',
'/ò|ó|ô|ø/i' => 'o',
'/ù|ú|ů|û/i' => 'u',
'/ș|ș|ş|Ș|Ș|Ş/i'=>'s',
'/ț|ţ|ț|Ț|Ţ/i'=>'t',
'/î/i' => 'i',
'/â/i' => 'a',
'/”|“|…|’|µ|º|’|‘|’|ldquo|rdquo|„|»|–/i' => '-',
'/[^[:alnum:]]/'=>' ',
'/[^\w\s]/' => ' ',
'/\\s+/' => '-',
'/\b([a-z]{1,3})\b/i'=>'',
'/\-+/' => '-'
);
$slug = preg_replace(array_keys($map),array_values($map),$slug);
return $slug;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment