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

Button background appears 3% darker than it should be

css twitter-bootstrap colors hsl

I'm adding CSS to a Bootstrap-based web app, to match a PDF from a designer. There's a button image, whose background color Seashore reports as rgb(0,186,158) aka hsl(171,100,36%). So I set the

Digression in the set of attributes in Richfaces 4.0?

java jsf file-upload richfaces

I'm implementing file uploading using Richfaces version 4.0. I've noticed, that there is quite a big differences between rich:fileUpload component in version 3.2 and the one in the latest version. ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.