/** * Convert a phrase to a URL-safe title. * * @param string phrase to convert * @param string word separator (- or _) * @return string */ public static function title($title, $separator = '-') { $separator = $separator === '-' ? '-' : '_'; // Replace accented characters by their unaccented equivalents $title = utf8::transliterate_to_ascii($title); // Remove all characters that are not the separator, a-z, 0-9, or whitespace $title = preg_replace('/[^' . $separator . 'a-z0-9\\s]+/', '', strtolower($title)); // Replace all separator characters and whitespace by a single separator $title = preg_replace('/[' . $separator . '\\s]+/', $separator, $title); // Trim separators from the beginning and end return trim($title, $separator); }