This function converts strings into a format that can be used in URLs. For example, the string “Mike’s Karate School” would be returned as “mikes-karate-school”. This function is recommended to be used on non-multibyte character sets. So this is not recommended for UTF-8, since certain PHP functions (like strtolower) should not be used on multibyte strings.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Returns a string in a URL friendly format. * @param string $str The input string. * @return string The URL friendly string. */ public static function getUrlFriendlyString($str) { // convert spaces to '-', remove characters that are not alphanumeric // or a '-', combine multiple dashes (i.e., '---') into one dash '-'. $str = ereg_replace("[-]+", "-", ereg_replace("[^a-z0-9-]", "", strtolower( str_replace(" ", "-", $str) ) ) ); return $str; } |
