Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'http://idealine.lt/files/interneto%20svetainiu%20optimizavimas/durys-durys%20interneto%20svetaines%20optimizavimas(4).csv');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
- $csv = curl_exec($curl);
- if($csv === false)
- {
- echo 'Curl error: ' . curl_error($curl);
- } else {
- curl_close();
- }
- $table = "<div style='width: 100%;' class='SEO-table-container' ><table class='SEO-table'>\n\n";
- //$f = fopen($csv, "r");
- $i = 0;
- while (($line = fgetcsv($csv, null, ';')) !== false) {
- if($i==0){
- $table .= "<thead>";
- }
- if($i==1){
- $table .= "<tbody>";
- }
- $table .= "<tr>";
- foreach ($line as $k => $cell) {
- $cell = $i == 0 && $k == 0 && $cell == '[keywords]' ? "Raktiniai žodžiai" : $cell;
- /*if($i==0&&$k>0){
- $cell = date_format('Y.m.d', date_create($cell));
- }*/
- $cell = preg_replace('/\,.0{0,2}$/', '', $cell);
- if(preg_match('/^[\d ]*$/', $cell, $match)) {
- if(preg_match('/\d+/', $match[0],$number)) {
- $cell = $number[0];
- } else {
- $cell = '';
- }
- } //this is the place where I want to parse out the thing I don't need
- $is_second_row_yellow = $i == 1 ? "<td class='SEO-table-top20 first-row'>" : "<td class='SEO-table-top20'>"; //pirma body eile geltoni bruksnys virsuje
- $is_second_row_green = $i == 1 ? "<td class='SEO-table-top10 first-row'>" : "<td class='SEO-table-top10'>"; //pirma body eile geltoni bruksnys virsuje
- $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
- $is_top_twenty = (is_numeric($cell) && $cell <= 20 && $cell > 10) ? $is_second_row_yellow : $is_second_row_right_not_yellow; //ar priklauso top 20
- $is_top_ten = (is_numeric($cell) && $cell <= 10) ? $is_second_row_green : $is_top_twenty; //ar priklauso top 10
- $is_rightest_header = ($k == 0 ? "<th class='SEO-first-column-header'>" : "<th class='SEO-table-header-dates'><span>"); //datos vertikaliai
- $is_second_row = $i == 1 ? "<td class='SEO-table-series first-row first-col'>" : "<td class='SEO-table-series-names first-col'>";
- $is_rightest_body = ($k == 0 ? $is_second_row : $is_top_ten);
- $cell_start = $i == 0 ? $is_rightest_header : $is_rightest_body;
- $cell_end = $i == 0 ? ($k == 0?"</th>":"</span></th>") : "</td>";
- $table .= $cell_start . $cell . $cell_end;
- }
- $table .= "</tr>\n";
- $table .= $i == 0 ? "</thead>" : "";
- $i++;
- }
- //fclose($f);
- $table .= "\n</tbody></table></div><br/>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement