0

I have tried this code but this gives me hyperlinks value only, but i want to extract all the data from table. My HTML table contains 1514 rows and 7 columns along with pagination its contains 125 number of pages to show. How can I get all data from the table and not just the hyperlinks?

  <?php
$ch=curl_init('https://datatables.net/examples/basic_init/alt_pagination.html');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $page = curl_exec($ch);

    preg_match('#<table[^>]*>(.+?)</table>#is', $page, $matches);
    foreach ($matches as &$match) {
         $match = $match;

    }
    echo '<table>';
        echo $matches[0];
    echo '</table>';
    ?>
  • it will be a lot easier for You if You use library like simple_html_dom, or DOMDocument [link](http://php.net/manual/en/domdocument.loadhtml.php) – Daimos Jun 24 '15 at 09:17
  • i want to get table data only not body text or paragraph. table contains many pages to display this data because data exists in large amount. – Khan Taimoor Malik Jun 24 '15 at 09:24
  • Sure, You have very nice manual there: [link](http://simplehtmldom.sourceforge.net/manual.htm) – Daimos Jun 24 '15 at 09:26
  • sorry @Daimos i have worked on it. but this link doesn't helped me. i am unable to extract the data – Khan Taimoor Malik Jun 24 '15 at 09:51

1 Answers1

0

Like i said before, there is no problem if You use simple html dom:

<?php
include('simple_html_dom.php');
$html = file_get_html('https://datatables.net/examples/basic_init/alt_pagination.html');
$tr = $html->find('table[id=example] tr');
foreach ($tr as $row)
{
    foreach ($row->find('td') as $td)
    {
        echo $td->plaintext.'<br/>';
    }
    echo '<hr/>';
}

sory i just saw that Alex have edited answer too.

PS. blank page? Put error_reporting(E_ALL); on the begining, You will see errors

Daimos
  • 1,473
  • 10
  • 28