/** * Converts a string to a normalized (no-spaces, non-letters) string * * @param string $subject original string * @return string normalized string */ public static function normalize($region) { // this is influenced by the setlocale() call with category LC_CTYPE; see PopulateDatabases.php $normalized = iconv('UTF-8', 'ASCII//TRANSLIT', $region); $normalized = Parser::strtolower($normalized); $normalized = str_replace("&", "", $normalized); $normalized = str_replace("'", "", $normalized); $normalized = str_replace("+", "-", $normalized); $normalized = str_replace(" ", "-", $normalized); $normalized = Parser::preg_replace('/\\W/', "-", $normalized); while (strstr($normalized, "--")) { $normalized = str_replace("--", "-", $normalized); } return $normalized; }
/** * Create a normalize category name (lowercase, just alpha and dashes) * from supplied name * * @param string $name [optional] will otherwise use name property */ public function setNormalizedFromName($name = null) { if ($name == null) { $name = $this->name; } // convert accented character and the like to just ascii equivalent // this is influenced by the setlocale() call with category LC_CTYPE $this->normalized = iconv('UTF-8', 'ASCII//TRANSLIT', $name); $this->normalized = Parser::strtolower($this->normalized); // strip out weird characters $this->normalized = str_replace("&", "", $this->normalized); $this->normalized = str_replace("'", "", $this->normalized); // convert these to dashes $this->normalized = str_replace("+", "-", $this->normalized); $this->normalized = str_replace(" ", "-", $this->normalized); // now any other non-word character to a dash $this->normalized = Parser::preg_replace('/\\W/', "-", $this->normalized); // pair multiple dashes down to one while (strstr($this->normalized, "--")) { $this->normalized = str_replace("--", "-", $this->normalized); } return $this; }