note 56814 deleted from function.usort by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 16:27:53 +0000 |
| Subject: | note 56814 deleted from function.usort by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176073@lists.php.net to get a copy of this message | ||
Note Submitter: markus dot meier at udo dot edu
----
gk at lka dot hu:
I've removed a few errors and moved both functions into one. The line with the prefix-check
did'nt work right.
<?php
function CompareUmlaut($astring, $bstring) {
$ALP = "AaÁáBbCcDdEeÉéFfGgHhIiÍiJjKkLlMmNnOoÓóÖöÕõPpQqRrSs" .
"TtUuÚúÜüÛûVvWwXxYyZz0123456789!?.()[]=%+-"
// find first differing char
$aLen = strlen($astring); $bLen = strlen($bstring);
for ($i=0; $i<$aLen && $i<$bLen && $astring[$i]==$bstring[$i]; $i++);
// if one string is the prefix of the other one, the shorter wins
if ($i == $aLen || $i == $bLen) return (strlen($astring) < strlen($bstring)) ? -1 : 1;
// otherwise depends on the first different char
$ALPL = strlen($ALP);
$ap = $bp = -1;
$j = 0;
while (($j < $ALPL) && (($ap == -1) || ($bp == -1))) {
if ($ALP[$j] == $astring[$i]) $ap = $j;
if ($ALP[$j] == $bstring[$i]) $bp = $j;
$j++;
}
return($ap < $bp) ? -1 : 1;
?>