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?
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.
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With