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;


$ch = curl_init();
$userAgent = 'Googlebot/2.1 (';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$target_url = '';
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);
    echo "<br> Think the page was nabbed";
    $dom = new DOMDocument();
    $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;



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.


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

Need Your Help