How to access @attribute from SimpleXML with PHP?

Spread the love

Sometimes, we want to access @attribute from SimpleXML with PHP.

In this article, we’ll look at how to access @attribute from SimpleXML with PHP.

How to access @attribute from SimpleXML with PHP?

To access @attribute from SimpleXML with PHP, we can use the attributes method.

For instance, we write

$xml->attributes()->{'field'};

to get the @attributes values with attributes.

Then we use {'field'} to get the value of the field with key 'field'.

Conclusion

To access @attribute from SimpleXML with PHP, we can use the attributes method.

Leave a Reply

Your email address will not be published. Required fields are marked *