function url_title($str, $separator = 'dash') { $separator = ($separator == 'underscore') ? '_' : '-'; $str = strtolower(htmlentities($str, ENT_COMPAT, 'UTF-8')); $str = preg_replace('/&(.)(acute|cedil|circ|grave|ring|tilde|uml);/', "$1", $str); $str = preg_replace('/([^a-z0-9]+)/', $separator, html_entity_decode($str, ENT_COMPAT, 'UTF-8')); $str = trim($str, $separator); return $str; }