SHARE
TWEET

Untitled

a guest Jan 11th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/php
  2. <?php
  3. function ft_split($str)
  4. {
  5.     return array_filter(explode(" ", implode(" ", array_filter(explode("\t", $str), "strlen"))), "strlen");
  6. }
  7. function cmp($a, $b)
  8. {
  9.     $i = 0;
  10.     $a = strtolower($a);
  11.     $b = strtolower($b);
  12.     if ($a == $b)
  13.         return 0;
  14.     while ($a[$i] && $a[$i] == $b[$i])
  15.         $i++;
  16.     $a = ord($a[$i]);
  17.     $b = ord($b[$i]);
  18.     if ($a >= 48 && $a <= 57)
  19.         $a = $a + 1000;
  20.     else if ($a < 97 || $a > 122)
  21.         $a = $a + 10000;
  22.     if ($b >= 48 && $b <= 57)
  23.         $b = $b + 1000;
  24.     else if ($b < 97 || $b > 122)
  25.         $b = $b + 10000;
  26.     return $a < $b ? -1 : 1;
  27. }
  28. $i = 1;
  29. $array = array();
  30. while ($i < $argc)
  31. {
  32.     $strs = ft_split($argv[$i]);
  33.     foreach ($strs as $str)
  34.         $array[] = $str;
  35.     $i++;
  36. }
  37. usort($array, "cmp");
  38. $i = 0;
  39. $len = count($array);
  40. while ($i < $len)
  41.     echo $array[$i++]."\n";
  42. ?>
RAW Paste Data
Top