/    Sign up×
Community /Pin to ProfileBookmark

foreach and xpath problem

Heres the code

[code]
XML
<accounts>
<account>
<username>test</username>
<cryptPassword>11-22-33-44-55-66-77</cryptPassword>
<created>2006-07-22T11:25:36.1512224-07:00</created>
<lastLogin>2006-07-22T22:44:00.5312464-07:00</lastLogin>
<totalGameTime>PT5H10M43.2376592S</totalGameTime>
<chars>
<char index=”0″>7263</char>
<char index=”1″>8104</char>
<char index=”2″>16593</char>
</chars>
<addressList count=”1″>
<ip>1.2.3.4</ip>
</addressList>
</account>

PHP

foreach ($xml->xpath(‘/accounts/account’) as $account) {
echo “<tr>”.
“<td>$account->username</td>”.
“<td>$account->addressList->ip</td>”.
“<td>$account->lastLogin</td>”.
“<td>$account->totalGameTime</td>”.
“</tr>”;
}
[/code]

Problem is the ip shows as ->ip instead of showing the actually IP.
Using php5.
So im guessing that the xpath only goes 1 tier. Is there anyway to get around this?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@intriviousAug 27.2006 — I do not have much experience with this, but this article has helped me in the past...

http://www.zend.com/php5/articles/php5-xmlphp.php
Copy linkTweet thisAlerts:
@prophitauthorAug 27.2006 — Hey intrivious thanks for that link.. I have been reading alot of the docs from zend..

now im running into this problem..

I finally got this working but for some reason its only showing the first ip.

I want it to display all of them for each user.

when i do this $data->[1] it will show the second variable.. is there a wild card that i can use? I tried * and @ / but none of those worked.
×

Success!

Help @prophit spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...