Only from specific table tag
Posted: Mon May 01, 2006 11:43 pm
Dear All,
I have a code such as below.My intention was to grab only data within a table tag from the respective html,but unable to do so as inside the html ,there's many table tag and no ID is given to each tag.
Can anyone please advice me on how i able to retrieve the data within the table tag that i wanted to grab?
I have a code such as below.My intention was to grab only data within a table tag from the respective html,but unable to do so as inside the html ,there's many table tag and no ID is given to each tag.
Can anyone please advice me on how i able to retrieve the data within the table tag that i wanted to grab?
Code: Select all
$ch = curl_init("http://localhost/test.htm");
curl_setopt($ch, CURLOPT_USERAGENT, "Internet Explorer");
ob_start();
curl_exec($ch);
curl_close($ch);
$str = ob_get_contents();
ob_end_clean();
preg_match("/\<table>(.*?)\<\/table\>/is", $str, $byname);
preg_match_all("/\<tr.*?>(.*?)\<\/tr\>.*?\<A.*?\>(.*?)\<BR\>/is", $byname[0], $moviedata);
$movies = array();
for($i=0; $i<count($moviedata[1]); $i++)
{
$score=$moviedata[1][$i];
$title=$moviedata[2][$i];
$title=preg_replace("/<.*?>/","",$title);
$title=html_entity_decode($title);
$movies[]=array($score,$title);
}Code: Select all
foreach($movies as $movie)
{
echo($movie[1]); echo($movie[0]);
}
[php][/php]