-function user_strcasecmp($a, $b)
-{
- return strcasecmp($a, $b);
+function user_strcasecmp($a, $b) {
+ global $delimiter;
+
+ /* Calculate the length of some strings. */
+ $a_length = strlen($a);
+ $b_length = strlen($b);
+ $min_length = min($a_length, $b_length);
+ $delimiter_length = strlen($delimiter);
+
+ /* Set the initial result value. */
+ $result = 0;
+
+ /* Check the strings... */
+ for ($c = 0; $c < $min_length; ++$c) {
+ $a_del = substr($a, $c, $delimiter_length);
+ $b_del = substr($b, $c, $delimiter_length);
+
+ if (($a_del == $delimiter) && ($b_del == $delimiter)) {
+ $result = 0;
+ } else if (($a_del == $delimiter) && ($b_del != $delimiter)) {
+ $result = 1;
+ } else if (($a_del != $delimiter) && ($b_del != $delimiter)) {
+ $result = -1;
+ } else {
+ $result = strcasecmp($a{$c}, $b{$c});
+ }
+
+ if ($result != 0) {
+ break;
+ }
+ }
+
+ /* If one string is a prefix of the other... */
+ if ($result == 0) {
+ if ($a_length < $b_length) {
+ $result = -1;
+ } else if ($a_length > $b_length) {
+ $result = 1;
+ }
+ }
+
+ return ($result);