- <?php
- $releases = utf8_encode(file_get_contents("/usr/www/users/mewmsin/sites/all/modules/paypal_sin/releases.txt"));
- #Split on linebreak.
- $releases = explode("\n", $releases);
- $newReleases = array();
- $i = 0;
- foreach($releases as $line => $value) {
- #Remove hidden linebreaks
- $value = str_replace(array("\n", "\r"), "", $value);
- if(empty($value)) {
- $i++;
- continue;
- } else {
- $newReleases[$i][] = $value;
- }
- }
- #Reset keys
- $newReleases = array_values($newReleases);
- #Impossible
- $impossible = array();
- $i = 0;
- $releases = array();
- foreach($newReleases as $key => $value) {
- #Format 1: Most with entries with 6, is the proper format.
- if(count($value) == 6) {
- continue; #
- $releases[$i]['date'] = $value[0];
- $releases[$i]['league'] = $value[1];
- $releases[$i]['title'] = $value[2];
- #Calc result, and remove it! Also check for postponed void and push
- if(preg_match("/push|void|voided|postponed/i", $value[5], $matches, PREG_OFFSET_CAPTURE)) {
- $releases[$i]['status'] = ucfirst($matches[0][0]);
- $releases[$i]['result'] = '';
- #Remove the last bit of the end
- $value[5] = substr($value[5], 0, $matches[0][1]);
- } else {
- $releases[$i]['status'] = '';
- #Either won or loss. Find the last number in the string.
- if(preg_match("/win|loss/i", $value[5], $findwinorloss, PREG_OFFSET_CAPTURE)) {
- #Fetch the win or loss units. Starting with isolating the win/loss
- $isolatedResult = substr($value[5], $findwinorloss[0][1]);
- #Fetch the digit with + or - in front
- if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
- #Remove plus if present
- $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
- }
- #Remove the last bit of the end
- $value[5] = substr($value[5], 0, $findwinorloss[0][1]);
- } else {
- #Win or loss not set | match not settled yet
- $releases[$i]['result'] = '';
- }
- }
- #Perhaps HTML colors should be applied here
- $releases[$i]['release'] = $value[3] ."<br />". $value[4] ."<br />". $value[5];
- $i++;
- continue;
- }
- #Format 2: with date ONLY in 1 key, and no league at all
- 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]))) {
- $releases[$i]['date'] = $value[0];
- $releases[$i]['league'] = '';
- $releases[$i]['title'] = $value[1];
- #Calc result, and remove it! Also check for postponed void and push
- if(preg_match("/push|void|voided|postponed/i", $value[4], $matches, PREG_OFFSET_CAPTURE)) {
- $releases[$i]['status'] = ucfirst($matches[0][0]);
- $releases[$i]['result'] = '';
- #Remove the last bit of the end
- $value[4] = substr($value[4], 0, $matches[0][1]);
- } else {
- $releases[$i]['status'] = '';
- #Either won or loss. Find the last number in the string.
- if(preg_match("/win|loss/i", $value[4], $findwinorloss, PREG_OFFSET_CAPTURE)) {
- #Fetch the win or loss units. Starting with isolating the win/loss
- $isolatedResult = substr($value[4], $findwinorloss[0][1]);
- #Fetch the digit with + or - in front
- if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
- #Remove plus if present
- $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
- }
- #Remove the last bit of the end
- $value[4] = substr($value[4], 0, $findwinorloss[0][1]);
- } else {
- #Win or loss not set | match not settled yet
- $releases[$i]['result'] = '';
- }
- }
- $releases[$i]['release'] = $value[2] ."<br />". $value[3] ."<br />". $value[4];
- $i++;
- continue;
- }
- #Format 3: with NO dates at all
- if(count($value) == 5 AND !preg_match("/^(\d){2}\/(\d){2}\/(\d){2}$/i", trim($value[0]))) {
- $releases[$i]['date'] = '';
- $releases[$i]['league'] = $value[0];
- $releases[$i]['title'] = $value[1];
- #Calc result, and remove it! Also check for postponed void and push
- if(preg_match("/push|void|voided|postponed/i", $value[4], $matches, PREG_OFFSET_CAPTURE)) {
- $releases[$i]['status'] = ucfirst($matches[0][0]);
- $releases[$i]['result'] = '';
- #Remove the last bit of the end
- $value[4] = substr($value[4], 0, $matches[0][1]);
- } else {
- $releases[$i]['status'] = '';
- #Either won or loss. Find the last number in the string.
- if(preg_match("/win|loss/i", $value[4], $findwinorloss, PREG_OFFSET_CAPTURE)) {
- #Fetch the win or loss units. Starting with isolating the win/loss
- $isolatedResult = substr($value[4], $findwinorloss[0][1]);
- #Fetch the digit with + or - in front
- if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
- #Remove plus if present
- $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
- }
- #Remove the last bit of the end
- $value[4] = substr($value[4], 0, $findwinorloss[0][1]);
- } else {
- #Win or loss not set | match not settled yet
- $releases[$i]['result'] = '';
- }
- }
- $releases[$i]['release'] = $value[2] ."<br />". $value[3] ."<br />". $value[4];
- $i++;
- continue;
- }
- #Format 3: with NO dates at all
- if(count($value) == 5 AND !preg_match("/^(\d){2}\/(\d){2}\/(\d){2}$/i", trim($value[0]))) {
- $releases[$i]['date'] = '';
- $releases[$i]['league'] = $value[0];
- $releases[$i]['title'] = $value[1];
- #Calc result, and remove it! Also check for postponed void and push
- if(preg_match("/push|void|voided|postponed/i", $value[4], $matches, PREG_OFFSET_CAPTURE)) {
- $releases[$i]['status'] = ucfirst($matches[0][0]);
- $releases[$i]['result'] = '';
- #Remove the last bit of the end
- $value[4] = substr($value[4], 0, $matches[0][1]);
- } else {
- $releases[$i]['status'] = '';
- #Either won or loss. Find the last number in the string.
- if(preg_match("/win|loss/i", $value[4], $findwinorloss, PREG_OFFSET_CAPTURE)) {
- #Fetch the win or loss units. Starting with isolating the win/loss
- $isolatedResult = substr($value[4], $findwinorloss[0][1]);
- #Fetch the digit with + or - in front
- if(preg_match("/[+|-]\d/i", $isolatedResult, $findresult)) {
- #Remove plus if present
- $releases[$i]['result'] = str_replace('+', '', $findresult[0]);
- }
- #Remove the last bit of the end
- $value[4] = substr($value[4], 0, $findwinorloss[0][1]);
- } else {
- #Win or loss not set | match not settled yet
- $releases[$i]['result'] = '';
- }
- }
- $releases[$i]['release'] = $value[2] ."<br />". $value[3] ."<br />". $value[4];
- $i++;
- continue;
- }
- #rest in manual
- $impossible[] = $value;
- continue;
- }
- core::par($impossible);
- ?>