How to retrieve data from @ xml attribute in PHP

后端 未结 2 1052
既然无缘
既然无缘 2021-01-26 05:49

Ok so I am stuck with this xml in PHP stuff. I have gotten pretty far considering its my first 3 hours into XML all together ever in my entire life.

I am having trouble

2条回答
  •  时光说笑
    2021-01-26 06:06

    You need to use the attributes() method to get the results as another class. So, for example, to get the date attribute:

    $myElement->attributes()->date
    

    Also note that it's not a string, it's a SimpleXML attribute. If you want to get its actual value, you need to cast it to string explicitly:

    (string)$myElement->attributes()->date
    

提交回复
热议问题