Of Slugs and Permalinks and PHP
Adapted from Rick Olsen’s permalink_fu.rb.
/**
Clean up a string and make it suitable for inclusion in a url.
@param $str The string to be slugified
@return a string containing a sanitized, url-safe version of $str
*/
function slugify ($str)
{
$slug = iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $str);
$slug = preg_replace('/\W+/', ' ', $slug);
$slug = trim($slug);
$slug = strtolower($slug);
$slug = preg_replace('/\ +/', '-', $slug);
return $slug;
}
