Skip to content

Instantly share code, notes, and snippets.

@cobyl
Last active December 19, 2015 21:39
Show Gist options
  • Save cobyl/6022161 to your computer and use it in GitHub Desktop.
Save cobyl/6022161 to your computer and use it in GitHub Desktop.
<?php
function generateSlug($string, $separator = '-') {
// nowa magia PHP 5.4 & intl
$transliterator = \Transliterator::create("Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();");
$string = $transliterator->transliterate($string);
//TODO przeklejone z starej funkcji - zapewne to powyżej większość z tego umie; część nadmiarowa
return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment