daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function getFirstNRowsFromTable($url,$n) {
  4.     $pageHTML = file_get_contents($url);
  5.    
  6.     $lastFoundPosition = 0;
  7.     $trsCount = 0;
  8.     $trsList = array();
  9.     do {
  10.         $foundPosition = strpos($pageHTML, '<tr>', $lastFoundPosition + 1);
  11.         if($foundPosition > 0) {
  12.             if($trsCount > 1) {
  13.                 $trsList[] = substr($pageHTML, $lastFoundPosition + 4, $foundPosition - $lastFoundPosition - 4);
  14.             }
  15.             $trsCount++;
  16.             $lastFoundPosition = $foundPosition;
  17.         }
  18.     }
  19.     while($trsCount < $n+2);
  20.    
  21.     return $trsList;
  22.    
  23. }
  24.  
  25. // gets table rows in array, each elements is string between <tr> and </tr>
  26. $tableRows = getFirstNRowsFromTable('http://posta.garda.sk/',4);
  27.  
  28. // print outs table
  29. $tableHTML = '<table>';
  30. foreach($tableRows as $tableRow) {
  31.     $tableHTML .= '<tr>' . $tableRow . '</tr>';
  32. }
  33. $tableHTML .= '</table>';
  34.  
  35. print $tableHTML;
  36.  
  37. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top