natasha_thomas Posted December 9, 2010 Share Posted December 9, 2010 Folks, I have an array having domain names & i have Coding for checking each element of this $valid array in an API and extract Information from XML. BUT, looks like the this code is not working or i am possibly not able to integrate this code properely. Another thing, this API allows to Check 19 Domain Max at a time, so this counter is already there in the code. Here is the Code: if(empty($valid)) return NULL; $rows=array(); while(count($valid)) { $this_set=array(); $count=0; while($count<19 && count($valid)) { $url=array_shift($valid); $this_set[]='item'. $count . '='. urlencode($url); $count++; } if(!count($this_set)) break; $query='http://lightapi.majesticseo.com/api_command.php?app_api_key=API_KEY&cmd=GetIndexItemInfo&items='. $count .'&' . implode('&',$this_set); $content=file_get_contents($query); preg_match('@<DataTable.*?Headers=\"(.*?)\"@',$content,$info); $headers=explode('|',$info[1]); preg_match_all('@<Row>(.*?)</Row>@',$content,$info); foreach($info[1] as $line) { $data=explode('|',$line); $info=array_combine($headers,$data); $rows[]=$info; } } if(empty($rows)) return NULL; return $rows; } I want to echo the output with: echo $Domain['Item'] .' '. $Domain['ACRank'] .' '. $Domain['ExtBackLinks'] .'<br />'. PHP_EOL; Could someone please help with this code? Regards Natasha T Quote Link to comment Share on other sites More sharing options...
requinix Posted December 9, 2010 Share Posted December 9, 2010 SimpleXML is a lot easier to use for parsing XML than a series of regular expressions. What does the XML look like and what parts do you want from it? Quote Link to comment Share on other sites More sharing options...
natasha_thomas Posted December 9, 2010 Author Share Posted December 9, 2010 SimpleXML is a lot easier to use for parsing XML than a series of regular expressions. What does the XML look like and what parts do you want from it? You can see the output here: http://lightapi.majesticseo.com/api_command.php?app_api_key=API_KEY&cmd=GetIndexItemInfo&items=1&item0=http://google.com I want to Extract ACRAnk element for Each domain name. Quote Link to comment Share on other sites More sharing options...
requinix Posted December 9, 2010 Share Posted December 9, 2010 For a start, // ... $query='http://lightapi.majesticseo.com/api_command.php?app_api_key=API_KEY&cmd=GetIndexItemInfo&items='. $count .'&' . implode('&',$this_set); $xml = new SimpleXMLElement($query, 0, true); if ((string)$xml["Code"] == "OK") { foreach ($xml->DataTables->DataTable as $table) { $headers = explode("|", (string)$table["Headers"]); $rows = array(); foreach ($table->Row as $row) { $rows[] = array_combine($headers, explode("|", (string)$row)); } print_r($rows); } } Was there a specific problem you had? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.