Created
February 13, 2013 14:31
-
-
Save Mezzle/4944982 to your computer and use it in GitHub Desktop.
UTF-8 Safe slugifier (PHP)
This file contains 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 slugify($text) | |
{ | |
// Swap out Non "Letters" with a - | |
$text = preg_replace('/[^\\pL\d]+/u', '-', $text); | |
// Trim out extra -'s | |
$text = trim($text, '-'); | |
// Convert letters that we have left to the closest ASCII representation | |
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); | |
// Make text lowercase | |
$text = strtolower($text); | |
// Strip out anything we haven't been able to convert | |
$text = preg_replace('/[^-\w]+/', '', $text); | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment