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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.