I have this form given:
<item><parameter name="a">3</parameter></item>
Is it possible to read the “a” with SimpleXML?
I have already tried $xml->item->parameter->getName(); but it only returns “parameter”.
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, use the
attributes()method fromSimpleXMLSimpleXML::attributes()
codepad example
Alternative solution is using
xpath()SimpleXML::xpath()
codepad example
xpath()always returns array (or false in case of error), this why you need to assign it to a var, or if you have php >= 5.4 you can use array dereferencing