Last active
December 19, 2015 21:39
-
-
Save cobyl/6022161 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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