Jump to content

Table to Array


drisate

Recommended Posts

Hey guys i need help with a CURL code. I need to retreive all the data in a table located at http://www.listenlive.nl/tvgenre.php?g=1&page=0 and parse the data to finish with an array that looks like this:

$row[0][station_name] = '3BTV';
$row[0][stream_link] = '420';
$row[0][stream_type] = 'wma';
$row[0][country] = 'United Kingdom';
$row[0][genre][0] = 'Variety';
$row[0][genre][1] = 'Alternative';
$row[0][genre][2] = 'Culture';
$row[0][rating] = '1/5';


I need that for each rows of the table where the first array number would increment $row[1], $row[2] ...
My PHP code is incomplete. I currently have a loop for all the TR's of the page ... and when i loop all the TD's inside the TR's it returns a load of crap ... I am unsure where to go from here. Any help would be apreciated thx


This is my code:
 

$ch = curl_init();
$categ[url] = 'http://www.listenlive.nl/tvgenre.php?g=1&page=0';
curl_setopt($ch, CURLOPT_URL, $categ[url]);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
curl_setopt($ch, CURLOPT_REFERER, $categ[url]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $nav);
$data2 = curl_exec($ch);
$dom2 = new DOMDocument();
libxml_use_internal_errors(true);
$dom2->loadHTML($data2);
$trs = $dom2->getElementsByTagName('tr');
foreach ($trs as $tr) {
echo "<pre>";
print_r($tr);
echo "</pre>";
}
Link to comment
https://forums.phpfreaks.com/topic/293568-table-to-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.