Created
July 17, 2012 08:38
-
-
Save benthebear/3128063 to your computer and use it in GitHub Desktop.
Generate Sortkey v.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function utf8_substr($str,$start) | |
{ | |
preg_match_all("/./u", $str, $ar); | |
if(func_num_args() >= 3) { | |
$end = func_get_arg(2); | |
return join("",array_slice($ar[0],$start,$end)); | |
} else { | |
return join("",array_slice($ar[0],$start)); | |
} | |
} | |
function string2sortkey($lemma){ | |
$charTable=array( | |
'A' => 2, | |
'a' => 2, | |
'Ä' => 2, | |
'ä' => 2, | |
'B' => 3, | |
'b' => 3, | |
'C' => 4, | |
'c' => 4, | |
'D' => 5, | |
'd' => 5, | |
'E' => 6, | |
'e' => 6, | |
'F' => 7, | |
'f' => 7, | |
'G' => 8, | |
'g' => 8, | |
'H' => 9, | |
'h' => 9, | |
'I' => 10, | |
'i' => 10, | |
'J' => 11, | |
'j' => 11, | |
'K' => 12, | |
'k' => 12, | |
'L' => 13, | |
'l' => 13, | |
'M' => 14, | |
'm' => 14, | |
'N' => 15, | |
'n' => 15, | |
'O' => 16, | |
'o' => 16, | |
'Ö' => 16, | |
'ö' => 16, | |
'P' => 17, | |
'p' => 17, | |
'Q' => 18, | |
'q' => 18, | |
'R' => 19, | |
'r' => 19, | |
'S' => 20, | |
's' => 20, | |
'ß' => 20, | |
'T' => 21, | |
't' => 21, | |
'U' => 22, | |
'u' => 22, | |
'Ü' => 22, | |
'ü' => 22, | |
'V' => 23, | |
'v' => 23, | |
'W' => 24, | |
'w' => 24, | |
'X' => 25, | |
'x' => 25, | |
'Y' => 26, | |
'y' => 26, | |
'Z' => 27, | |
'z' => 27 | |
); | |
$lemma=(string)$lemma; | |
print "String: ".$lemma."\n"; | |
$sort=0; | |
$multiply=1000000; | |
for($i=0;$i<4;$i++) | |
{ | |
$current = 0; | |
if(strlen($lemma)<=$i) | |
{ | |
//$title ist zu ende | |
} | |
else | |
{ | |
$char = utf8_substr($lemma, $i, 1); | |
if(array_key_exists($char,$charTable)) | |
{ | |
print "[".$char."]"; | |
$current=$charTable[$char]; | |
} | |
else | |
{ print "[1]"; | |
$current = 1; | |
} | |
} | |
$current=$current*($multiply); | |
$multiply=$multiply/100; | |
$sort=$sort+$current; | |
} | |
return $sort; | |
} | |
print " ".string2sortkey("Überzeit")."\n"; | |
print " ".string2sortkey("öffentlich-rechtlich")."\n"; | |
print " ".string2sortkey("Außen")."\n"; | |
print " ".string2sortkey("Augen")."\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment