PHP simpleXML Scope

TofeExofe

New Member
This is my first time using XML documents. What I'm trying to do is extract some information from a spotify search. e.g. this page: Spotify ResultsI'm not that good with scoping, everything I know so far has been from tutorials. What I want the end results to look like is somthing like this:\[code\](Album Name) - (Artist Name) (year)(track number) - (Track Name) - (length)(track number) - (Track Name) - (length)(track number) - (Track Name) - (length)...\[/code\]Here is the code I have so far. \[code\]<?php function print_r2($val){ echo '<pre>'; print_r($val); echo '</pre>';}$URL = "http://ws.spotify.com/lookup/1/?uri=spotify:album:77Tgq2oSMvgP4Y9pBVKRJa&extras=trackdetail";$xml = simplexml_load_file($URL) or die("Error: Cannot create object");//print_r2($xml);foreach($xml->children() as $album){ echo($album->name); echo($album->artist->name); echo($album->released); foreach($album->children() as $track => $data){ echo $data->{'track-number'}; echo(" - "); echo $data->name; echo(" - "); echo $data->length; echo "<br />"; }}?>\[/code\]The Problem that I'm having is the Artist Name and Year is not showing, and also it's putting in more " - " then there needs to be. (guessing it has something to do with children() but not outputting any data.)Also, I was thinking about having this information saved into an array and processing that data into a SQL database. If you know of a better way of writing it with the array that would be awesome. (kill two birds with one stone).
 
Back
Top