Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can simplexml be used to rifle through html?

Tags:

I would like to grab data from a table without using regular expressions. I've enjoyed using simplexml for parsing RSS feeds and would like to know if it can be used to grab a table from another page.

Eg. Grab the page with curl or simply file_get_contents(); then use simplexml to grab contents?

like image 960
chris Avatar asked Jul 09 '11 15:07

chris


People also ask

What is SimpleXML in Web technology?

SimpleXML is an extension that allows us to easily manipulate and get XML data. SimpleXML provides an easy way of getting an element's name, attributes and textual content if you know the XML document's structure or layout.

What is SimpleXML extension?

SimpleXML is a PHP extension that allows users to easily manipulate/use XML data. It was introduced in PHP 5 as an object oriented approach to the XML DOM providing an object that can be processed with normal property selectors and array iterators.

Which of the following SimpleXML elements method are used to add an attribute name with value to the element?

The SimpleXMLElement::attributes() function is an inbuilt function in PHP which is used to retrieve the attributes and its value from an XML tag in a SimpleXML object.


1 Answers

You can use the loadHTML function from the DOM module, and then import that DOM into SimpleXML via simplexml_import_dom:

$html = file_get_contents('http://example.com/'); $doc = new DOMDocument(); $doc->loadHTML($html); $sxml = simplexml_import_dom($doc); 
like image 191
phihag Avatar answered Oct 24 '22 20:10

phihag