Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.01 KB | None | 0 0
  1. <?php
  2.  
  3. class Parser
  4. {
  5.     private $base = array();
  6.     private $path = array();
  7.  
  8.     private function LoadBase()
  9.     {
  10.         $s = file_get_contents('info/base.txt');
  11.         $arr = explode("====================", $s);
  12.         for ($i = 0, $n = sizeof($arr); $i < $n; $i++) {
  13.             $arr[$i] = explode("\n", $arr[$i]);
  14.         }
  15.         $accounts = $arr;
  16.         $all = sizeof($accounts);
  17.  
  18.         for ($i = 0; $i < $all; $i++) {
  19.             if (sizeof($accounts[$i]) < 4) {
  20.                 unset($accounts[$i]);
  21.             }
  22.         }
  23.         sort($accounts);
  24.         return $accounts;
  25.     }
  26.  
  27.     private function createdir()
  28.     {
  29.         $this->path = date("F j, Y, g:i:s a");
  30.         mkdir($this->path, 0777);
  31.     }
  32.  
  33.     function templatetext($massive)
  34.     {
  35.  
  36.         $s = $massive;
  37.         $all = sizeof($s);
  38.         $string = "====================\n";
  39.         for ($i = 0; $i < $all; $i++) {
  40.  
  41.             $keys = sizeof($s[$i]);
  42.             for ($k = 1; $k < $keys; $k++) {
  43.                 $string = $string . $s[$i][$k] . "\n";
  44.             }
  45.             $string = $string . "====================\n";
  46.             $string = $string . "====================\n";
  47.  
  48.         }
  49.         return $string;
  50.     }
  51.  
  52.     function save($massive, $file)
  53.     {
  54.  
  55.         $s = $massive;
  56.         $all = sizeof($s);
  57.         $string = "====================\n";
  58.         for ($i = 0; $i < $all; $i++) {
  59.  
  60.             $keys = sizeof($s[$i]);
  61.             for ($k = 1; $k < $keys; $k++) {
  62.                 $string = $string . $s[$i][$k] . "\n";
  63.             }
  64.             $string = $string . "\n====================\n";
  65.             $string = $string . "====================\n";
  66.  
  67.         }
  68.         $file = fopen($this->path . "/" . $file . ".txt", "a+");
  69.         fwrite($file, print_r($string, 1000));
  70.         fclose($file);
  71.     }
  72.  
  73.     function save2($massive, $file)
  74.     {
  75.  
  76.         $s = $massive;
  77.  
  78.         $string = "====================\n";
  79.  
  80.         $string = $string . $s . "\n";
  81.         $string = $string . "\n====================\n";
  82.         $string = $string . "====================\n";
  83.  
  84.  
  85.         $file = fopen($this->path . "/" . $file . ".txt", "a+");
  86.         fwrite($file, print_r($string, 1));
  87.         fclose($file);
  88.     }
  89.  
  90.     /*private function check_Limited()
  91.     {
  92.         $limitedarr = $this->base;
  93.         $all = sizeof($limitedarr);
  94.  
  95.  
  96.         $lim = array();
  97.  
  98.         for($i = 0; $i < $all;$i++)
  99.         {
  100.             $sum = $limitedarr[$i][13];
  101.             $string = preg_replace('~[^0-9,.]+~','',$sum);
  102.             if($string > 100)
  103.             {
  104.                 $string = $limitedarr[$i][6];
  105.                 $s = preg_replace('~[^+-]+~','',$string);
  106.                 if (strcmp($s,"+") == 0)
  107.                 {
  108.                    array_push($lim,$limitedarr[$i]);
  109.                 }
  110.             }
  111.         }
  112.         $this->createdir();
  113.         $file=fopen($this->path . "/Limited_good.txt","w");
  114.         $text = $this->templatetext($lim);
  115.         fwrite($file,print_r($text,1000));
  116.         fclose($file);
  117.     }*/
  118.  
  119.     private
  120.     function check_Limited()
  121.     {
  122.         $limitedarr = $this->base;
  123.         $all = sizeof($limitedarr);
  124.  
  125.  
  126.         $lim = array();
  127.  
  128.         for ($i = 0; $i < $all; $i++) {
  129.  
  130.             if ($this->check_Balance($limitedarr[$i][13])) {
  131.                 $string = $limitedarr[$i][6];
  132.                 $s = preg_replace('~[^+-]+~', '', $string);
  133.                 if (strcmp($s, "+") == 0) {
  134.                     array_push($lim, $limitedarr[$i]);
  135.                 }
  136.             }
  137.         }
  138.         $file = fopen($this->path . "/Limited_good.txt", "w");
  139.         $text = $this->templatetext($lim);
  140.         fwrite($file, print_r($text, 1));
  141.         fclose($file);
  142.     }
  143.  
  144.     private
  145.     function check_Balance($massive)
  146.     {
  147.         $sum = $massive;
  148.         $string = preg_replace('~[^0-9,.]+~', '', $sum);
  149.         if ($string > 100) {
  150.             return true;
  151.         }
  152.     }
  153.  
  154.     private function getCountryCode($c)
  155.     {
  156.  
  157.        $code = explode("-",$c);
  158.        $sizz = sizeof($code);
  159.        if($sizz == 2)
  160.        {
  161.                return trim($code[1]);
  162.        }
  163.        else
  164.        {
  165.            return "Unknown";
  166.        }
  167.  
  168.  
  169.     }
  170.  
  171.     private function getBank($b)
  172.     {
  173.  
  174.         $bank = explode("-",$b);
  175.         $sizz = sizeof($bank);
  176.         if($sizz == 2)
  177.         {
  178.             return true;
  179.         }
  180.         else
  181.         {
  182.             return false;
  183.         }
  184.  
  185.  
  186.     }
  187.  
  188.     function check_Country()
  189.     {
  190.         $base = $this->base;
  191.         $all = sizeof($base);
  192.         $country = array();
  193.  
  194.         for ($i = 0; $i < $all; $i++) {
  195.             //1 === proverka po balansy;
  196.             $balance = $base[$i][13];
  197.             $t = preg_replace('~[^0-9,.]+~', '', $balance);
  198.  
  199.             if ($t > 100)
  200.             {
  201.  
  202.                 $lol = $this->getCountryCode($base[$i][7]);
  203.                 $file = fopen($this->path . "/" . $lol . ".txt", "a+");
  204.                 $t = implode("\n", $base[$i]);
  205.                 fwrite($file, print_r("====================\n". trim($t) . "\n====================\n" , 1));
  206.                 fclose($file);
  207.                 unset($base[$i]);
  208.                 sort($base);
  209.  
  210.             }
  211.  
  212.  
  213.             //1 ==========================
  214.  
  215.             // === proverka po gody
  216.             $all = sizeof($base);
  217.             $card = $base[$i][14];
  218.             $c = preg_replace('~[^0-9/]+~', '', $card);
  219.             $d_e = explode("/", $c);
  220.             $allde = sizeof($d_e);
  221.             if ($allde > 1) {
  222.                 if ($d_e[0] > 0 or $d_e[1] > 0) {
  223.                     $min_card = mktime(0, 0, 0, 2017, 01, 0);
  224.                     $max_card = mktime(0, 0, 0, $d_e[1], $d_e[0], 0);
  225.                     if ($min_card < $max_card)
  226.                     {
  227.                         $lol = $this->getCountryCode($base[$i][7]);
  228.                         $file = fopen($this->path . "/" . $lol . ".txt", "a+");
  229.                         $t = implode("\n", $base[$i]);
  230.                         fwrite($file, print_r("====================\n". trim($t) . "\n====================\n" , 1));
  231.                         fclose($file);
  232.                         unset($base[$i]);
  233.                         sort($base);
  234.                     }
  235.                 }
  236.             }
  237.             //============================
  238.  
  239.             // === proverka po banky
  240.             $all = sizeof($base)-1;
  241.             $bank = $this->getBank($base[$i][15]);
  242.  
  243.             $b = explode("-", $bank);
  244.             if(sizeof($b) > 2)
  245.             {
  246.                 if (trim($b[1]) != null)
  247.                 {
  248.                     $lol = $this->getCountryCode($base[$i][7]);
  249.                     $file = fopen($this->path . "/" . $lol . ".txt", "a+");
  250.                     $t = implode("\n", $base[$i]);
  251.                     fwrite($file, print_r("====================\n". trim($t) . "\n====================\n" , 1));
  252.                     fclose($file);
  253.  
  254.                 }
  255.             }
  256.  
  257.  
  258.  
  259.             //===========================
  260.  
  261.  
  262.         }
  263.         /*print_r($country);
  264.         $allc = sizeof($country);
  265.         for($l=0; $l < $allc; $l++)
  266.         {
  267.  
  268.             $file = fopen($this->path . "/" . $country[$l] . ".txt","a+");
  269.             print_r($base[3]);
  270.             //$text = $this->templatetext($base[1]);
  271.             //write($file,print_r($text,1000));
  272.             fclose($file);
  273.             //print_r($base[$l]);
  274.             $l = $l + 1;
  275.         }*/
  276.  
  277.     }
  278.  
  279.     public
  280.     function run()
  281.     {
  282.         echo "<pre>";
  283.         echo '<script language="JavaScript">
  284.              alert("Файл успешно загружен! начинаю работу!");
  285.              </script>
  286.              ';
  287.  
  288.         $this->base = $this->LoadBase();
  289.         $this->createdir();
  290.         $this->check_Limited();
  291.         $this->check_Country();
  292.         echo '<script language="JavaScript">
  293.              alert("Парсер успешно закочил свою работу!");
  294.              </script>
  295.              ';
  296.     }
  297. }
  298.  
  299. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement