SimpleXMLElement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shanecody
Forum Newbie
Posts: 23
Joined: Fri May 08, 2009 4:12 pm

SimpleXMLElement

Post by shanecody »

When I try to access the @attributes created by simplexml i get the following error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in C:\wamp\www\php_sandbox\rex_test.php on line 11

the code is a such:
foreach ($xml->token as $value){
echo "key == " .$value->@attributes['key'];
}

Is there a setting in PHP that is wrong?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: SimpleXMLElement

Post by requinix »

@attributes is not a valid variable name so you can't use it that way.

Try SimpleXML's array syntax version instead.

Code: Select all

$value["key"]
shanecody
Forum Newbie
Posts: 23
Joined: Fri May 08, 2009 4:12 pm

Re: SimpleXMLElement

Post by shanecody »

Thanks that did it.
Post Reply