-1

I'm fetching data from another website using file_get_contents(), but I need to extract a multiple tables records with class inputpanelfields,

$d = new DOMDocument  
libxml_use_internal_errors(true)  
$d->loadHTML($html)   
$table = $x->query('//table[contains(@class, "inputpanelfields")]')  

How can I do this?

Tony Stark
  • 8,064
  • 8
  • 44
  • 63
  • $html = file_get_contents('https://www.example.com'); $d = new DOMDocument; libxml_use_internal_errors(true); $d->loadHTML($html); libxml_clear_errors(); $x = new DOMXPath($d); $table = $x->query('//table[contains(@class, "inputpanelfields")]'); i want the cpmlete data in html format. – Bhavnish Narang Feb 15 '13 at 06:29

1 Answers1

0

DomDocument::saveHTML() takes an argument to only save a subset of the document. So you can for example output the HTML of the first matched table like this:

echo $d->saveHTML($table[0]);
Fabian Schmengler
  • 24,155
  • 9
  • 79
  • 111
  • $html = file_get_contents('example.com'); $d = new DOMDocument; libxml_use_internal_errors(true); $d->loadHTML($html); libxml_clear_errors(); $x = new DOMXPath($d); $table = $x->query('//table[contains(@class, "inputpanelfields")]'); i m using this complete code bro...bt this returns me a string...can u pls give me the com plete code how to save it html format – Bhavnish Narang Feb 15 '13 at 08:12
  • It's a HTML string, what more would you want? Save it to a file? Then use `saveHTMLFile()` instead. – Fabian Schmengler Feb 15 '13 at 08:25
  • sir i want to print the data in same format from i fetched the data...like if i fetched data from table them i want to print data in table format – Bhavnish Narang Feb 15 '13 at 10:28