Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getFirstNRowsFromTable($url,$n) {
- $pageHTML = file_get_contents($url);
- $lastFoundPosition = 0;
- $trsCount = 0;
- $trsList = array();
- do {
- $foundPosition = strpos($pageHTML, '<tr>', $lastFoundPosition + 1);
- if($foundPosition > 0) {
- if($trsCount > 1) {
- $trsList[] = substr($pageHTML, $lastFoundPosition + 4, $foundPosition - $lastFoundPosition - 4);
- }
- $trsCount++;
- $lastFoundPosition = $foundPosition;
- }
- }
- while($trsCount < $n+2);
- return $trsList;
- }
- // gets table rows in array, each elements is string between <tr> and </tr>
- $tableRows = getFirstNRowsFromTable('http://posta.garda.sk/',4);
- // print outs table
- $tableHTML = '<table>';
- foreach($tableRows as $tableRow) {
- $tableHTML .= '<tr>' . $tableRow . '</tr>';
- }
- $tableHTML .= '</table>';
- print $tableHTML;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement