sorn53 Posted November 18, 2015 Share Posted November 18, 2015 <?php $xml = @simplexml_load_file("device.xml/"); echo '<pre>'; print_r($xml); echo '</pre>' <? The above gives, SimpleXMLElement Object ( [@attributes] => Array ( [publicAddress] => 127.0.0.1 ) [Device] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => (Firefox) [publicAddress] => 1.1.1.1 [product] => =Web [productVersion] => 2.0 [platform] => Firefox [platformVersion] => 40.0 [device] => Linux [model] => [vendor] => [provides] => [clientIdentifier] => fdrk1q [version] => 2.4 [id] => 3950 [token] => pqAGXG [createdAt] => 1447 [lastSeenAt] => 14477 [screenResolution] => [screenDensity] => ) [0] => ) How would i create a php page to show the following from the xml content above. Public IP: 1.1.1.1 ClientIdentifier: fdrk1q Created : 1447797662 <-- convert this to readable date also Thanks in advance..... Quote Link to comment Share on other sites More sharing options...
requinix Posted November 18, 2015 Share Posted November 18, 2015 The publicAddress and clientIdentifier are attributes on the . (string)$xml->Device["publicAddress"] (string)$xml->Device["clientIdentifier"]I don't know where you're getting the created time from but use date to make it more readable. 1 Quote Link to comment Share on other sites More sharing options...
sorn53 Posted November 18, 2015 Author Share Posted November 18, 2015 The publicAddress and clientIdentifier are attributes on the <Device>. (string)$xml->Device["publicAddress"] (string)$xml->Device["clientIdentifier"]I don't know where you're getting the created time from but use date to make it more readable. Thank you for your reply, how would i use to show the values of each string ? (string)$xml->Device["publicAddress"] (string)$xml->Device["clientIdentifier"] Both are date stamps i guess i can use date to convert to more readable format. [createdAt] => 1447797662 [lastSeenAt] => 1447797662 Quote Link to comment Share on other sites More sharing options...
requinix Posted November 18, 2015 Share Posted November 18, 2015 how would i use to show the values of each string ? (string)$xml->Device["publicAddress"] (string)$xml->Device["clientIdentifier"] I dunno. echo? print? Mobile app? You decide. Both are date stamps i guess i can use date to convert to more readable format. [createdAt] => 1447797662 [lastSeenAt] => 1447797662 That would be why I suggested it. Quote Link to comment Share on other sites More sharing options...
sorn53 Posted November 18, 2015 Author Share Posted November 18, 2015 (edited) I dunno. echo? print? Mobile app? You decide. I meant how can i foreach for all the (string)$xml->Device["publicAddress"] foreach ($xml->Device["publicAddress"] as $value) { echo "Public Address: $value <br>"; } Yes im not a expert or even a notice but im trying to learn, Edited November 18, 2015 by sorn53 Quote Link to comment Share on other sites More sharing options...
Barand Posted November 18, 2015 Share Posted November 18, 2015 try foreach ($xml->Device as $device) { echo (string)$device['clientIdentifier'] . '<br/>'; } 1 Quote Link to comment Share on other sites More sharing options...
sorn53 Posted November 19, 2015 Author Share Posted November 19, 2015 try foreach ($xml->Device as $device) { echo (string)$device['clientIdentifier'] . '<br/>'; } That worked perfectly thank you 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.