Advertisement
linccce

Untitled

Mar 20th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.64 KB | None | 0 0
  1.                  $curl = curl_init();
  2.                  
  3.                    
  4.                 curl_setopt($curl, CURLOPT_URL, 'http://idealine.lt/files/interneto%20svetainiu%20optimizavimas/durys-durys%20interneto%20svetaines%20optimizavimas(4).csv');  
  5.                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  6.                    
  7.                 $csv = curl_exec($curl);
  8.                
  9.                 if($csv === false)
  10.                 {
  11.                     echo 'Curl error: ' . curl_error($curl);
  12.                 } else {
  13.                     curl_close();
  14.                 }
  15.                  
  16.                 $table = "<div style='width: 100%;' class='SEO-table-container' ><table class='SEO-table'>\n\n";
  17.                     //$f = fopen($csv, "r");
  18.                     $i = 0;
  19.                     while (($line = fgetcsv($csv, null, ';')) !== false) {
  20.                         if($i==0){
  21.                             $table .= "<thead>";
  22.                         }
  23.  
  24.                         if($i==1){
  25.                             $table .= "<tbody>";
  26.                         }
  27.  
  28.                         $table .= "<tr>";
  29.                         foreach ($line as $k => $cell) {
  30.  
  31.                             $cell = $i == 0 && $k == 0 && $cell == '[keywords]' ? "Raktiniai žodžiai" : $cell;
  32.  
  33.                             /*if($i==0&&$k>0){
  34.                                 $cell = date_format('Y.m.d', date_create($cell));
  35.                             }*/
  36.  
  37.                             $cell = preg_replace('/\,.0{0,2}$/', '', $cell);
  38.  
  39.                             if(preg_match('/^[\d ]*$/', $cell, $match)) {
  40.                                 if(preg_match('/\d+/', $match[0],$number)) {
  41.                                     $cell = $number[0];
  42.                                 } else {
  43.                                     $cell = '';
  44.                                 }
  45.                             } //this is the place where I want to parse out the thing I don't need
  46.  
  47.                             $is_second_row_yellow = $i == 1 ? "<td class='SEO-table-top20 first-row'>" : "<td class='SEO-table-top20'>"; //pirma body eile geltoni bruksnys virsuje
  48.  
  49.                             $is_second_row_green = $i == 1 ? "<td class='SEO-table-top10 first-row'>" : "<td class='SEO-table-top10'>"; //pirma body eile geltoni bruksnys virsuje
  50.  
  51.                             $is_second_row_right_not_yellow = $i == 1 ? "<td class='SEO-table-values first-row'>" : "<td class='SEO-table-values'>"; //pirma body eile ne geltoni bruksnys virsuje
  52.  
  53.                             $is_top_twenty = (is_numeric($cell) && $cell <= 20 && $cell > 10) ? $is_second_row_yellow : $is_second_row_right_not_yellow; //ar priklauso top 20
  54.  
  55.                             $is_top_ten = (is_numeric($cell) && $cell <= 10) ? $is_second_row_green : $is_top_twenty; //ar priklauso top 10
  56.  
  57.                             $is_rightest_header = ($k == 0 ? "<th class='SEO-first-column-header'>" : "<th class='SEO-table-header-dates'><span>"); //datos vertikaliai
  58.  
  59.                             $is_second_row = $i == 1 ? "<td class='SEO-table-series first-row first-col'>" : "<td class='SEO-table-series-names first-col'>";
  60.  
  61.                             $is_rightest_body = ($k == 0 ? $is_second_row : $is_top_ten);
  62.  
  63.                             $cell_start = $i == 0 ? $is_rightest_header : $is_rightest_body;
  64.  
  65.                             $cell_end = $i == 0 ? ($k == 0?"</th>":"</span></th>") : "</td>";
  66.  
  67.                             $table .= $cell_start . $cell . $cell_end;
  68.  
  69.                         }
  70.                         $table .= "</tr>\n";
  71.                         $table .= $i == 0 ? "</thead>" : "";
  72.                         $i++;
  73.                     }
  74.                     //fclose($f);
  75.                     $table .= "\n</tbody></table></div><br/>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement