How to retrieve data from @ xml attribute in PHP

后端 未结 2 1053
既然无缘
既然无缘 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
    
    0 讨论(0)
  • 2021-01-26 06:06

    Access attributes of an element just as you would elements of an array:

    (string) $xml->property[0]->availability->month[0]['date']

    Edited to add the cast.

    0 讨论(0)
提交回复
热议问题