Jump to content

Recommended Posts

<?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.....

 

Link to comment
https://forums.phpfreaks.com/topic/299509-parse-content-from-xml-url-using-php/
Share on other sites

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.
  • Like 1

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

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.

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 by sorn53
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.