I have a curl script that ends like this:
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
The $data string it a HTML page with a table on that I want to strip so that I can store the data into a MYSQL database, I have tried using DOM with commands such as:
// new dom object
$dom = new DOMDocument();
//load the html
$html = str_get_html($returned_content2);
$dom->strictErrorChecking = false;
//discard white space
$dom->preserveWhiteSpace = false;
//the table by its tag name
$tables = $dom->getElementsByTagName('table');
//get all rows from the table
$rows = $tables->item(0)->getElementsByTagName('tr');
// loop over the table rows
foreach ($rows as $row)
{
// get each column by tag name
$cols = $row->getElementsByTagName('td');
// echo the values
echo $cols->item(0)->nodeValue.'<br />';
echo $cols->item(1)->nodeValue.'<br />';
echo $cols->item(2)->nodeValue;
}
}
But keep getting the error:
Fatal error: Call to a member function getElementsByTagName() on a non-object in /home/sdsd/dfdsfsdfds/sdfsdfs/table.php on line 178