At some point in the near future I'll be adding in
a per-language sort
order adjustment, so that various sorted lists should turn out in more
or less correct order for a change. :)
I'd appreciate pointers to descriptions of various languages' sorting
requirements so I can try to get them right.
I have recently made a little PHP script that sort correctly in danish.
You can find the result here:
http://www.wikipedia.dk/wiki/sortering.php
The code snippet below does the actual sorting, maybe it can give you some
inspiration on how to do it.
The key functions here is strtr() which replaces all the weird characters
with the correct characters for sorting in danish, and usort() which does
the actual sorting.
<?
function cmp ($a, $b)
{
$compa = strtr($a,
"SOZsozY¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿABCDEF
GHIJKLMNOPQRSTUVWXYZ",
"sozsozyyuaaaaaøåceeeeiiiidnoooooæuuuuysaaaaaøåceeeeiiiionoooooæuuuuyyabcdef
ghijklmnopqrstuvwxyz");
$compb = strtr($b,
"SOZsozY¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿABCDEF
GHIJKLMNOPQRSTUVWXYZ",
"sozsozyyuaaaaaøåceeeeiiiidnoooooæuuuuysaaaaaøåceeeeiiiionoooooæuuuuyyabcdef
ghijklmnopqrstuvwxyz");
for ($i=0 ; $i<strlen($compa) ; $i++)
{
if (strlen($compb)==$i)
{
if ($_POST["Orden"]=="Stigende")
{
return -1;
}
else
{
return 1;
}
}
if ($compa{$i} > $compb{$i})
{
if ($_POST["Orden"]=="Stigende")
{
return 1;
}
else
{
return -1;
}
}
else if ($compa{$i} < $compb{$i})
{
if ($_POST["Orden"]=="Stigende")
{
return -1;
}
else
{
return 1;
}
}
}
return 0;
}
$tekst = $_POST["foo"];
$myarray = explode("\n",$tekst );
usort($myarray, "cmp");
$tekst = implode("\n",$myarray);
print $tekst;
?>
Regards
Christian
BTW: I have bought wikipedia.dk and made it redirect to
da.wikipedia.org,
and it will stay that way untill the folks at
da.wikipedia.org might decide
otherwise. I will also place little scripts like this danish sorting script
on
http://www.wikipedia.dk/wiki/sortering.php