Created
June 29, 2012 16:51
-
-
Save ryun/3019151 to your computer and use it in GitHub Desktop.
Slugify helper function
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
function to_slug($str, $replace=array(), $delimiter='_', $maxLength=200) | |
{ | |
if(!empty($replace)) | |
{ | |
$str = str_replace((array)$replace, ' ', $str); | |
} | |
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str); | |
$clean = preg_replace("%[^-/+|\w ]%", '', $clean); | |
$clean = strtolower(trim(substr($clean, 0, $maxLength), $delimiter)); | |
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); | |
return $clean; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment