No i tu się dzieje coś dziwnego. Niby ładnie to trawi ale sobie nie radzi.
Przykład.
object(SimpleXMLElement)#106 (1) {
[0]=>
string(17) "76561198002230331"
}
string(9) "steamID64"
NULL
string(0) ""
4 kolejne wartości: $k{czyli kolejny element}, $k->getName(){nazwa elementu}, $k[0]{pierwsza wartość elementu}, trim($k[0])){obcięta pierwsza wartość elementu};
w $k widać że jest [0]=> string(17) "76561198002230331", czyli pierwszy element ma wartość "76561198002230331" == OK
$k->getName() daję ładnie nazwę "steamID64" == OK
ale $k[0] nie pobiera się, chociaż w $k widać że jest ta wartość.
Chcesz to przetestuj ten kod:
<?php
$xml = simplexml_load_file("http://steamcommunity.com/profiles/76561198002230331?xml=1");
$vals = array();
RecurseXML($xml,$vals);
foreach($vals as $key=>$value)
print("{$key} = {$value}<BR>\n");
function RecurseXML($xml,&$vals,$parent="") {
$childs=0;
$child_count=-1; # Not realy needed.
$arr=array();
foreach ($xml->children() as $key=>$value) {
if (in_array($key,$arr)) {
$child_count++;
} else {
$child_count=0;
}
$arr[]=$key;
$k=($parent == "") ? "$key.$child_count" : "$parent.$key.$child_count";
$childs=RecurseXML($value,$vals,$k);
if ($childs==0) {
$vals[$k]= (string)$value;
}
}
return $childs;
}
?>
Powinien wyświetlić coś jak:
steamID64.0 = 76561198002230331
steamID.0 = Grajkownia.com | haerde
onlineState.0 = offline
stateMessage.0 = Last Online: 1 hrs, 10 mins ago
privacyState.0 = public
visibilityState.0 = 3
avatarIcon.0 = http://media.steampowered.com/steamcommunity/public/images/avatars/7f/7fc364f2d4fbd8ee33bb445b3da93433fa76fa08.jpg
avatarMedium.0 = http://media.steampowered.com/steamcommunity/public/images/avatars/7f/7fc364f2d4fbd8ee33bb445b3da93433fa76fa08_medium.jpg
avatarFull.0 = http://media.steampowered.com/steamcommunity/public/images/avatars/7f/7fc364f2d4fbd8ee33bb445b3da93433fa76fa08_full.jpg
vacBanned.0 = 0
isLimitedAccount.0 = 0
customURL.0 = haerde
memberSince.0 = November 1, 2008
steamRating.0 = 0.2
hoursPlayed2Wk.0 = 0.7
headline.0 = Satanicus Sacramentum Muerte!
location.0 = Nysa, Opole, Poland
realname.0 = Oskar Elll
Ale znając życie nie będzie u ciebie żadnych wartości, czyli będzie coś jak:
steamID64.0 =
steamID.0 =
onlineState.0 =
stateMessage.0 =
privacyState.0 =
visibilityState.0 =
avatarIcon.0 =
avatarMedium.0 =
avatarFull.0 =
vacBanned.0 =
isLimitedAccount.0 =
customURL.0 =
memberSince.0 =
steamRating.0 =
hoursPlayed2Wk.0 =
headline.0 =
location.0 =
realname.0 =