Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function slugify($value, $transliteration = false)
- {
- if (extension_loaded('intl') && $transliteration == true) {
- $transliterator = \Transliterator::create('Any-Latin; Latin-ASCII');
- $value = $transliterator->transliterate($value);
- }
- //
- $str = preg_replace('/\s+/', '-', trim($value)); // Trim and remove spaces
- $str = str_replace('_', '-', $str); // Underscores to dashes
- $str = preg_replace('/[^\pL0-9-]/u', '', strtolower($str)); // Only alpha-numeric and dashes are permitted
- $str = preg_replace('/-+/', '-', $str); // Prevent 2+ dashes from appearing together
- // Don't end in a dash
- if( substr($str, -1, 1) === '-' ){
- $str = substr($str, 0, -1);
- }
- return $str;
- }
Add Comment
Please, Sign In to add comment