Return to Snippet

Revision: 5047
at February 7, 2008 07:57 by sammy


Updated Code
function CleaningAString($string)
  {
      //$string = strtolower($string);
      
      // Fix german special chars
      $string = preg_replace('/[äÄ]/', 'ae', $string);
      $string = preg_replace('/[üÜ]/', 'ue', $string);
      $string = preg_replace('/[öÖ]/', 'oe', $string);
      $string = preg_replace('/[ß]/', 'ss', $string);
      
      // Replace other special chars
      $specialCharacters = array(
	 '#' => 'sharp',
	 '$' => 'dollar',
	 '%' => 'prozent',	//'percent',
	 '&' => 'und',		//'and',
	 '@' => 'at',
	 '.' => 'punkt',	//'dot',
	 '€' => 'euro',
	 '+' => 'plus',
	 '=' => 'gleich',	//'equals',
	 '§' => 'paragraph',
      );
      
      while (list($character, $replacement) = each($specialCharacters)) {
          $string = str_replace($character, '-' . $replacement . '-', $string);
      }
      
      $string = strtr($string, 
	"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ",
	"AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn"
      );
      
      // Remove all remaining other unknown characters        
      $string = preg_replace('/[^a-zA-Z0-9\-]/', '-', $string);
      $string = preg_replace('/^[\-]+/', '', $string);
      $string = preg_replace('/[\-]+$/', '', $string);
      $string = preg_replace('/[\-]{2,}/', '-', $string);
      
      return $string;
  }

Revision: 5046
at February 7, 2008 07:55 by sammy


Initial Code
function FormatAsKey($string)
  {
      //$string = strtolower($string);
      
      // Fix german special chars
      $string = preg_replace('/[äÄ]/', 'ae', $string);
      $string = preg_replace('/[üÜ]/', 'ue', $string);
      $string = preg_replace('/[öÖ]/', 'oe', $string);
      $string = preg_replace('/[ß]/', 'ss', $string);
      
      // Replace other special chars
      $specialCharacters = array(
	 '#' => 'sharp',
	 '$' => 'dollar',
	 '%' => 'prozent',	//'percent',
	 '&' => 'und',		//'and',
	 '@' => 'at',
	 '.' => 'punkt',	//'dot',
	 '€' => 'euro',
	 '+' => 'plus',
	 '=' => 'gleich',	//'equals',
	 '§' => 'paragraph',
      );
      
      while (list($character, $replacement) = each($specialCharacters)) {
          $string = str_replace($character, '-' . $replacement . '-', $string);
      }
      
      $string = strtr($string, 
	"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ",
	"AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn"
      );
      
      // Remove all remaining other unknown characters        
      $string = preg_replace('/[^a-zA-Z0-9\-]/', '-', $string);
      $string = preg_replace('/^[\-]+/', '', $string);
      $string = preg_replace('/[\-]+$/', '', $string);
      $string = preg_replace('/[\-]{2,}/', '-', $string);
      
      return $string;
  }

Initial URL

                                

Initial Description
Wandelt eine Zeichenkette, die Sonderzeichen enthält, in eine Zeichenkette ohne Sonderzeichen.

Converts a string, the special characters contains in a string without special characters.

Initial Title
Cleaning a string

Initial Tags

                                

Initial Language
PHP