How to get data from a table on a webpage in PHP

I am trying to get data from four rows each with two rows from a webpage. After some reading around I have tried the following code;

<?PHP

    require('simple_html_dom.php');
$ch = curl_init();
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$target_url = 'http://www.boz.zm/(S(0m5hxtuuoex4xqjkzrpbsh55))/Startpage.aspx';
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$html = curl_exec($ch);
if (!$html) 
{
    echo "<br />cURL error number:" .curl_errno($ch);
    echo "<br />cURL error:" . curl_error($ch);
    exit;
}
else
{
    echo "<br> Think the page was nabbed";
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $xpath = new DOMXpath($dom);
    $tableData = array();

    foreach($xpath->query('//table[@id="_ctl0_zmain_Dg_ExchangeRates"]/tr[position()<5]') as $node)
    {
        $rowData = array();
        foreach($xpath->query('td', $node) as $cell)
        {
            $rowdat = $cell->textContent;
            $rowData[] = $rowdat;
        }
        $tableDate[]=$rowData;
    }
    print_r($tableData);

}


?>

Only returns an empty array. I would like to put the values of each row in a multidimensional array so I can easily work with them. Any ideas on how I can achieve this task, even if its a different approach from what im trying to do I dont mind.? Thanks in Advance.

Answers


It is only a mistyping: you have written : $tableDate[]=$rowData; instead of $tableData[]=$rowData;


Need Your Help