maddogandnoriko Posted April 14, 2009 Share Posted April 14, 2009 I have an xml page loaded into a simplexml object. I am trying to create an array of SeriesNames from the simple xml object to pass to smarty. When I add a SeriesName to the $shows array, it adds it as an object not as the elements text value. PHP: $counter=0; $shows=array(); $seriesURL='http://www.thetvdb.com/api/GetSeries.php?seriesname=bones'; $data = simplexml_load_file($seriesURL); foreach($data->Series as $series){ $shows["$counter"]['name']=$series->SeriesName; $counter++; } The XML: <Data> − <Series> <seriesid>75682</seriesid> <language>en</language> <SeriesName>Bones</SeriesName> <banner>graphical/75682-g3.jpg</banner> − <Overview> Dr. Temperance Brennan is a highly skilled forensic anthropologist at the Jeffersonian Institute in Washington, DC. When the standard methods of identifying a body are useless - when the remains are so badly decomposed, burned or destroyed that CSI gives up - law enforcement calls in Brennan for her uncanny ability to read clues left behind in the victim's bones. Special agent Seeley Booth of the FBI's Homicide Investigations Unit is the exception. A former Army sniper, Booth mistrusts science and scientists - the "squints," as he calls them -- who pore over the physical evidence of a crime. </Overview> <FirstAired>2005-09-13</FirstAired> <IMDB_ID>tt0460627</IMDB_ID> <zap2it_id>SH754201</zap2it_id> <id>75682</id> </Series> − <Series> <seriesid>76818</seriesid> <language>en</language> <SeriesName>Hearts and Bones</SeriesName> − <Overview> Hearts and Bones series one is a seven-part one-hour drama which explores the lives, loves and careers of a group of friends from Coventry who all move to London. Emma is in a seven year relationship with Mark Rose, with whom she has a son Sam. She marries him although she loves his brother Rich-a butcher. Rich lives with his girlfriend Louise who is a hairdresser but he finds the temptation of a dalliance with Emma hard to resist especially when his relationship with Louise comes under strain when Louise's mother becomes ill. There is also Emma's best pal Amanda who's single since splitting up with her investment banker boyfriend Michael; Romance novel writer Sinead is besotted with Mark but turns to the Internet for love when he marries Emma. Series two picks up the story three months on. Mark has left and Emma and Rich haven't spoken since their affair. Emma is being shunned by Michael and Sinead. Michael is once more estranged from Amanda. Only Emma, Amanda and Louis </Overview> <FirstAired>2000-07-01</FirstAired> <id>76818</id> </Series> − <Series> <seriesid>70881</seriesid> <language>en</language> <SeriesName>Fitz and Bones</SeriesName> <FirstAired>1981-10-01</FirstAired> <id>70881</id> </Series> </Data> Here is the array I end up with including the unwanted simplexml objects: Array ( [0] => Array ( [name] => SimpleXMLElement Object ( [0] => Bones ) ) [1] => Array ( [name] => SimpleXMLElement Object ( [0] => Hearts and Bones ) ) [2] => Array ( [name] => SimpleXMLElement Object ( [0] => Fitz and Bones ) ) ) Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 14, 2009 Share Posted April 14, 2009 force it to a string like so: $shows["$counter"]['name'] = (string)$series->SeriesName; Quote Link to comment Share on other sites More sharing options...
maddogandnoriko Posted April 14, 2009 Author Share Posted April 14, 2009 That did it! Also the following also worked, added quotes. "$series->SeriesName" Thank you so much, maddogandnoriko Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.