- Thumann
- Wednesday, July 11th, 2007 at 4:29:27am MDT
- <?php
- //Where is our xml?
- $url = "http://somehost.somedomain.com/xmlfile.xml";
- //Make sure we use the correct user agent so we acutally get valid xml back
- $user_agent = "Mozilla/5.0 Firefox/2.0.0.1";
- //Our curl function
- function curl_string ($url,$user_agent){
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
- $result = curl_exec ($ch);
- curl_close($ch);
- return $result;
- }
- //Fetch it
- $xml = curl_string($url_page,$user_agent);
- //Our XML parse class
- class xml2Array {
- var $resParser;
- var $strXmlData;
- function parse($strInputXML) {
- if(!$this->strXmlData) {
- }
- return $this->arrOutput;
- }
- function tagOpen($parser, $name, $attrs) {
- }
- function tagData($parser, $tagData) {
- }
- else {
- }
- }
- }
- function tagClosed($parser, $name) {
- }
- }
- //Create the new XML object so we can make our array
- $objXML = new xml2Array();
- //Create the array from our xml source by using the parser
- $arrOutput = $objXML->parse($xml);
- //Echo the array
- echo '<pre>';
- echo '</pre>';
- //Define a few variables to use further on..
- $name = $value['attrs']['NAME'];
- $class = $value['attrs']['CLASS'];
- ?>
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.