Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.97 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. function convert_long($a)
  4. {
  5.         $r = array();
  6.         $i = 0;
  7.  
  8.         foreach($a AS $o)
  9.         {
  10.                 if(is_int($o))
  11.                 {
  12.                         $r[$i] = $o;
  13.                         $i++;
  14.                 }
  15.                 else
  16.                 {
  17.                         $ra = explode('-', $o);
  18.                         $t = range($ra['0'], $ra['1']);
  19.                         foreach ($t AS $s)
  20.                         {
  21.                                 $r[$i] = $s;
  22.                                 $i++;
  23.                         }
  24.                 }
  25.         }
  26.         return $r;
  27. }
  28.  
  29. function convert_short($a)
  30. {
  31.         $r = array();
  32.         $t = array();
  33.         $i = 0;
  34.         $l = false;
  35.  
  36.         foreach($a AS $o)
  37.         {
  38.                 if($l!=false && $l+1==$o && (!isset($t['0']) || $t['0']=='+'))
  39.                 {
  40.                         $t['0'] = '+';
  41.                         $t[] = $o;
  42.                 }
  43.                 else if($l!=false && $l-1==$o && (!isset($t['0']) || $t['0']=='-'))
  44.                 {
  45.                         $t['0'] = '-';
  46.                         $t[] = $o;
  47.                 }
  48.                 else if($l!=false && isset($t['1']) && count($t)>3)
  49.                 {
  50.                         $r[$i-1] .= '-'.$l;
  51.                         $t = array();
  52.                         $r[$i] = $o;
  53.                         $i++;
  54.                 }
  55.                 else if($l!=false && isset($t['1']))
  56.                 {
  57.                         $r[$i] = $l;
  58.                         $i++;
  59.                         $t = array();
  60.                         $r[$i] = $o;
  61.                         $i++;
  62.                 }
  63.                 else
  64.                 {
  65.                         $r[$i] = $o;
  66.                         $i++;
  67.                 }
  68.                 $l = $o;
  69.         }
  70.         return $r;
  71. }
  72.  
  73. ?>