Created
December 5, 2013 21:09
-
-
Save curiositry/7813943 to your computer and use it in GitHub Desktop.
A function to convert strings to SEO friendly URL slugs from www.cubiq.org
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
setlocale(LC_ALL, 'en_US.UTF8'); | |
function toAscii($str, $replace=array(), $delimiter='-') { | |
if( !empty($replace) ) { | |
$str = str_replace((array)$replace, ' ', $str); | |
} | |
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str); | |
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); | |
$clean = strtolower(trim($clean, '-')); | |
$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