Skip to content

Instantly share code, notes, and snippets.

@frozonfreak
Created December 29, 2014 03:44
Show Gist options
  • Save frozonfreak/fa580da45c425e41f04c to your computer and use it in GitHub Desktop.
Save frozonfreak/fa580da45c425e41f04c to your computer and use it in GitHub Desktop.
Clean URL PHP
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