Jump to content

add xml object to array


maddogandnoriko

Recommended Posts

I have an xml page loaded into a simplexml object, and have used xpath as to just work on the episode tags.

 

$episode_data=$this->xml->xpath("/Data/Episode[id=.$tvdbID.]");

 

When I echo the value of 'SeasonNumber' ($episode->SeasonNumber) I get a number as expected. But if I add $episode->SeasonNumber to an array:

$this->seasonList[] = (int)$episode->SeasonNumber[0];

 

It adds a simplexml object to the array not the number as echoed before, in the end I am trying to end up with a simple array of season #'s.

 

I have tried to include tenough info but not sure.

 

Thank you for any help,

 

  maddogandnoriko

Link to comment
https://forums.phpfreaks.com/topic/153179-add-xml-object-to-array/
Share on other sites

Not familiar with xpath, so no idea what your code is actually doing, but I do notice a lack of contents access instead of a node.

Shouldn't you be access it's contents instead?

 

$this->seasonList[] = $episode->SeasonNumber[0]->textContent;

 

Would be good if you could post your actual code including the foreach, inside [ code] [/ code] tags and surrounded by <?php ?> tags for syntax highlighting.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.