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

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: None  |  size: 7.21 KB  |  hits: 8  |  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. $releases = utf8_encode(file_get_contents("/usr/www/users/mewmsin/sites/all/modules/paypal_sin/releases.txt"));
  3.  
  4.        
  5.         #Split on linebreak.
  6.         $releases = explode("\n", $releases);
  7.        
  8.        
  9.        
  10.         $newReleases = array();
  11.        
  12.         $i = 0;
  13.        
  14.         foreach($releases as $line => $value) {
  15.        
  16.                 #Remove hidden linebreaks
  17.                 $value = str_replace(array("\n", "\r"), "", $value);
  18.  
  19.                 if(empty($value)) {
  20.  
  21.                         $i++;
  22.                         continue;
  23.                        
  24.                 } else {
  25.                         $newReleases[$i][] = $value;
  26.                        
  27.                 }
  28.                
  29.         }
  30.        
  31.         #Reset keys
  32.         $newReleases = array_values($newReleases);
  33.        
  34.         #Impossible
  35.         $impossible = array();
  36.         $i = 0;
  37.         $releases = array();
  38.         foreach($newReleases as $key => $value) {
  39.                
  40.                 #Format 1: Most with entries with 6, is the proper format.
  41.                 if(count($value) == 6) {
  42.                         continue; #
  43.                         $releases[$i]['date'] = $value[0];
  44.                         $releases[$i]['league'] = $value[1];
  45.                         $releases[$i]['title'] = $value[2];
  46.                        
  47.                         #Calc result, and remove it! Also check for postponed void and push
  48.                         if(preg_match("/push|void|voided|postponed/i", $value[5], $matches, PREG_OFFSET_CAPTURE)) {
  49.                                
  50.                                 $releases[$i]['status'] = ucfirst($matches[0][0]);
  51.                                 $releases[$i]['result'] = '';
  52.                                
  53.                                 #Remove the last bit of the end
  54.                                 $value[5] = substr($value[5], 0, $matches[0][1]);
  55.  
  56.                         } else {
  57.                                
  58.                                 $releases[$i]['status'] = '';
  59.                                
  60.                                 #Either won or loss. Find the last number in the string.
  61.                                 if(preg_match("/win|loss/i", $value[5], $findwinorloss, PREG_OFFSET_CAPTURE)) {
  62.  
  63.                                         #Fetch the win or loss units. Starting with isolating the win/loss
  64.                                         $isolatedResult = substr($value[5], $findwinorloss[0][1]);
  65.                                        
  66.                                         #Fetch the digit with + or - in front
  67.                                         if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
  68.                                                
  69.                                                 #Remove plus if present
  70.                                                 $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
  71.                                                
  72.                                         }
  73.                                        
  74.                                         #Remove the last bit of the end
  75.                                         $value[5] = substr($value[5], 0, $findwinorloss[0][1]);
  76.                                        
  77.                                 } else {
  78.                                        
  79.                                         #Win or loss not set | match not settled yet
  80.                                         $releases[$i]['result'] = '';
  81.                                 }
  82.                                
  83.                                
  84.                                
  85.                                
  86.                         }
  87.                        
  88.                         #Perhaps HTML colors should be applied here
  89.                         $releases[$i]['release'] = $value[3] ."<br />". $value[4] ."<br />". $value[5];
  90.                         $i++;
  91.                         continue;
  92.                 }
  93.                
  94.                
  95.                
  96.                
  97.                 #Format 2: with date ONLY in 1 key, and no league at all
  98.                 if(count($value) == 5 AND preg_match("/^(\d){2}\/(\d){2}\/(\d){2}$/i", trim($value[0])) AND !preg_match("/(league|lig|tennis)/i", trim($value[1]))) {
  99.        
  100.                         $releases[$i]['date'] = $value[0];
  101.                         $releases[$i]['league'] = '';
  102.                         $releases[$i]['title'] = $value[1];
  103.                        
  104.                
  105.                        
  106.                         #Calc result, and remove it! Also check for postponed void and push
  107.                         if(preg_match("/push|void|voided|postponed/i", $value[4], $matches, PREG_OFFSET_CAPTURE)) {
  108.                                
  109.                                 $releases[$i]['status'] = ucfirst($matches[0][0]);
  110.                                 $releases[$i]['result'] = '';
  111.                                
  112.                                 #Remove the last bit of the end
  113.                                 $value[4] = substr($value[4], 0, $matches[0][1]);
  114.  
  115.                         } else {
  116.                                
  117.                                 $releases[$i]['status'] = '';
  118.                        
  119.                                 #Either won or loss. Find the last number in the string.
  120.                                 if(preg_match("/win|loss/i", $value[4], $findwinorloss, PREG_OFFSET_CAPTURE)) {
  121.                
  122.                                         #Fetch the win or loss units. Starting with isolating the win/loss
  123.                                         $isolatedResult = substr($value[4], $findwinorloss[0][1]);
  124.                                        
  125.                                         #Fetch the digit with + or - in front
  126.                                         if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
  127.                                                
  128.                                                 #Remove plus if present
  129.                                                 $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
  130.                                                
  131.                                         }
  132.                                        
  133.                                         #Remove the last bit of the end
  134.                                         $value[4] = substr($value[4], 0, $findwinorloss[0][1]);
  135.                                        
  136.                                        
  137.                                 } else {
  138.                                        
  139.                                         #Win or loss not set | match not settled yet
  140.                                         $releases[$i]['result'] = '';
  141.                                 }
  142.                                
  143.                                
  144.                                
  145.                                
  146.                         }
  147.                        
  148.                         $releases[$i]['release'] = $value[2] ."<br />". $value[3] ."<br />". $value[4];
  149.        
  150.                         $i++;
  151.                
  152.                         continue;
  153.                        
  154.                 }
  155.                
  156.                
  157.                 #Format 3: with NO dates at all
  158.                 if(count($value) == 5 AND !preg_match("/^(\d){2}\/(\d){2}\/(\d){2}$/i", trim($value[0]))) {
  159.        
  160.                         $releases[$i]['date'] = '';
  161.                         $releases[$i]['league'] = $value[0];
  162.                         $releases[$i]['title'] = $value[1];
  163.                        
  164.                
  165.                        
  166.                         #Calc result, and remove it! Also check for postponed void and push
  167.                         if(preg_match("/push|void|voided|postponed/i", $value[4], $matches, PREG_OFFSET_CAPTURE)) {
  168.                                
  169.                                 $releases[$i]['status'] = ucfirst($matches[0][0]);
  170.                                 $releases[$i]['result'] = '';
  171.                                
  172.                                 #Remove the last bit of the end
  173.                                 $value[4] = substr($value[4], 0, $matches[0][1]);
  174.  
  175.                         } else {
  176.                                
  177.                                 $releases[$i]['status'] = '';
  178.                        
  179.                                 #Either won or loss. Find the last number in the string.
  180.                                 if(preg_match("/win|loss/i", $value[4], $findwinorloss, PREG_OFFSET_CAPTURE)) {
  181.                
  182.                                         #Fetch the win or loss units. Starting with isolating the win/loss
  183.                                         $isolatedResult = substr($value[4], $findwinorloss[0][1]);
  184.                                        
  185.                                         #Fetch the digit with + or - in front
  186.                                         if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
  187.                                                
  188.                                                 #Remove plus if present
  189.                                                 $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
  190.                                                
  191.                                         }
  192.                                        
  193.                                         #Remove the last bit of the end
  194.                                         $value[4] = substr($value[4], 0, $findwinorloss[0][1]);
  195.                                        
  196.                                        
  197.                                 } else {
  198.                                        
  199.                                         #Win or loss not set | match not settled yet
  200.                                         $releases[$i]['result'] = '';
  201.                                 }
  202.                                
  203.                                
  204.                                
  205.                                
  206.                         }
  207.                        
  208.                         $releases[$i]['release'] = $value[2] ."<br />". $value[3] ."<br />". $value[4];
  209.                         $i++;
  210.                
  211.                         continue;
  212.                        
  213.                 }
  214.                
  215.                
  216.                 #Format 3: with NO dates at all
  217.                 if(count($value) == 5 AND !preg_match("/^(\d){2}\/(\d){2}\/(\d){2}$/i", trim($value[0]))) {
  218.        
  219.                         $releases[$i]['date'] = '';
  220.                         $releases[$i]['league'] = $value[0];
  221.                         $releases[$i]['title'] = $value[1];
  222.                        
  223.                
  224.                        
  225.                         #Calc result, and remove it! Also check for postponed void and push
  226.                         if(preg_match("/push|void|voided|postponed/i", $value[4], $matches, PREG_OFFSET_CAPTURE)) {
  227.                                
  228.                                 $releases[$i]['status'] = ucfirst($matches[0][0]);
  229.                                 $releases[$i]['result'] = '';
  230.                                
  231.                                 #Remove the last bit of the end
  232.                                 $value[4] = substr($value[4], 0, $matches[0][1]);
  233.  
  234.                         } else {
  235.                                
  236.                                 $releases[$i]['status'] = '';
  237.                        
  238.                                 #Either won or loss. Find the last number in the string.
  239.                                 if(preg_match("/win|loss/i", $value[4], $findwinorloss, PREG_OFFSET_CAPTURE)) {
  240.                
  241.                                         #Fetch the win or loss units. Starting with isolating the win/loss
  242.                                         $isolatedResult = substr($value[4], $findwinorloss[0][1]);
  243.                                        
  244.                                         #Fetch the digit with + or - in front
  245.                                         if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
  246.                                                
  247.                                                 #Remove plus if present
  248.                                                 $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
  249.                                                
  250.                                         }
  251.                                        
  252.                                         #Remove the last bit of the end
  253.                                         $value[4] = substr($value[4], 0, $findwinorloss[0][1]);
  254.                                        
  255.                                        
  256.                                 } else {
  257.                                        
  258.                                         #Win or loss not set | match not settled yet
  259.                                         $releases[$i]['result'] = '';
  260.                                 }
  261.                                
  262.                                
  263.                                
  264.                                
  265.                         }
  266.                        
  267.                         $releases[$i]['release'] = $value[2] ."<br />". $value[3] ."<br />". $value[4];
  268.                         $i++;
  269.                
  270.                         continue;
  271.                        
  272.                 }
  273.                
  274.                
  275.                
  276.                
  277.                
  278.                
  279.                 #rest in manual
  280.                 $impossible[] = $value;
  281.                 continue;
  282.        
  283.                
  284.                
  285.                
  286.        
  287.                
  288.                
  289.         }
  290.        
  291.  
  292.         core::par($impossible);
  293. ?>