How to Convert Strings into a URL Friendly Format Using PHP

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;
}

Joimo’s Expansion into New Activities

In 2011, Joimo took a big leap and started offering a variety of different sports and recreational activities.  I’m happy to say that we now offer bowling, dodgeball, indoor soccer, outdoor soccer,  and kickball!

Joimo Dodgeball

Photo from San Diego Co-ed Dodgeball!