Valleriani
asked on
PHP - SimpleXML .. A way to cycle through all information in receieved XML data
I've attached the code on what I have so far.
Pretty much what I do is get the data sent back to me in XML and parse it using SIMPLEXML. What I want to grab is a few specific variables, anything that matches, [name], [companyName], [streetAddress]. etc.. The thing is, the data recieved is always different, so sometimes there more then one streetAddress, companyName, etc.. And I need to grab them all.
What would be the best way to grab ALL the required data fields regardless on how many records there are.. the goal is to add it all to a text file so it can be used as a blacklist on our end (aka blacklisted domains/companies/etc for our servers.)
Thanks!
Pretty much what I do is get the data sent back to me in XML and parse it using SIMPLEXML. What I want to grab is a few specific variables, anything that matches, [name], [companyName], [streetAddress]. etc.. The thing is, the data recieved is always different, so sometimes there more then one streetAddress, companyName, etc.. And I need to grab them all.
What would be the best way to grab ALL the required data fields regardless on how many records there are.. the goal is to add it all to a text file so it can be used as a blacklist on our end (aka blacklisted domains/companies/etc for our servers.)
Thanks!
if (!empty($_POST)) {
$domain = $_POST['domain'];
$arecord = gethostbyname($domain);
$url = 'http://whois.arin.net/rest/ip/' . $arecord . '/pft';
$data = file_get_contents($url);
$obj = SimpleXML_Load_String($data);
print_r($obj);
}
?>
<html><body>
<h4>Whois Blacklist Checker</h4>
<form action="index.php" method="post">
Enter Domain: <input name="domain" type="text" />
<input type="submit" />
</form>
</body></html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
bportlock - copy the code and submit any web domain - there you can see the XML
@Roads - I must be in dopey mode this morning I tried http://whois.arin.net/rest/ip/yahoo.com/pft and got Your request could not be processed because it is not composed correctly.
:-(
:-(
Try through the code snippet form - it returns XML.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
For this I believe I am going to be able to use both..
// for name array
foreach($obj->children() as $value)
array_push($mynemearray,$v alue);
So that POC, ORG, NET, etc are the same, then I can use your snippet to process through the array. I believe that should work but need to check it out in a few.
Thanks both so far!
// for name array
foreach($obj->children() as $value)
array_push($mynemearray,$v
So that POC, ORG, NET, etc are the same, then I can use your snippet to process through the array. I believe that should work but need to check it out in a few.
Thanks both so far!
ASKER
Both are very helpful and I used a mix of both to complete this issue. Thank you!
<record>
<address>
....data etc...
</address>
</record>
and for repeats
<record>
<address>
....data etc...
</address>
<address>
....data etc...
</address>
</record>
so for this I would do something like
foreach ($obj->address as $anAddress ) {
.... process one address group
}
With seeing the XML it's hard to be more specific.