Page 1 of 1

SimpleXMLElement

Posted: Tue Jun 16, 2009 12:06 pm
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?

Re: SimpleXMLElement

Posted: Tue Jun 16, 2009 2:38 pm
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"]

Re: SimpleXMLElement

Posted: Wed Jun 17, 2009 11:45 am
by shanecody
Thanks that did it.