0

Hey
Im having a bit of trouble due to creating a media player playlist and using xml to input the directory variables to flash. I haven't really used xml much apart from that.

Anyway...

I need the variables from my XML file in a variable ready to print in php on my website.
If you don't understand have a look at the code and Im sure you will...

playlist.xml

<?xml version="1.0" encoding="utf-8"?>
<PLAYLIST>
<SONG URL="track1.mp3" TITLE="song title 1" ARTIST="artist 1"/>
<SONG URL="track2.mp3" TITLE="song title 2" ARTIST="artist 2"/>
<SONG URL="track3.mp3" TITLE="song title 3" ARTIST="artist 3"/>
</PLAYLIST>

Playlist.php

echo "You currently have * number of songs on your playlist";
echo "<br>";

* I'd like to be able to count the amount of songs in the playlist.. and then print out simple a-href's for each of the files like such:

<a href='SONG URL'>SONG TITLE - SONG ARTIST</a>

Any help here would be greatly appreciated.

Thanks in advanced!

3
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by whiteyoh
0

Although I rarely use xml there is a xml reader library and perhaps that will be the key to solving your problem. I haven't used the xml libraries before since I haven't used xml much but hopefully that link should be of some use to you.

0

Hey
I've managed to get the XML into a php array. But I don't understand how it's structured.
Using this:

print_r($assoc);

I get this output in my browser:

Array ( [0] => Array ( [tag] => PLAYLIST [value] => Array ( [0] => Array ( [tag] => SONG [value] => [attributes] => Array ( [URL] => audio/track1.mp3 [TITLE] => Reece Stanton [ARTIST] => Moonlight in D ) ) [1] => Array ( [tag] => SONG [value] => [attributes] => Array ( [URL] => audio/track2.mp3 [TITLE] => DJ KIDEVA [ARTIST] => Live stage rock - origional ) ) [2] => Array ( [tag] => SONG [value] => [attributes] => Array ( [URL] => audio/track3.mp3 [TITLE] => DJ KIDEVA [ARTIST] => Pop the horn - origional ) ) ) ) )

I need to count how many songs are in the playlist and then print each url link. Any ideas

Thanks

0

The following will count how many songs:

echo 'There are ';
echo count($array[0]['value']);
echo ' songs.';

Then to display each link use the following

for ($i=0;$i<count($array[0]['value']);$i++) {
echo $array[0]['value'][$i]['attributes']['URL'];
}

Also the styled version of your array output can be viewed with the following.

echo '<xmp>';
print_r($array);
echo '</xmp>';

That will add new lines and spacing.

0

I've had a read through but I really don't understand. Could you give me some examples to how I should structure this from my php array to deleting a song in the playlist.xml

Thanks

0

Hi,

I have a similar thread going on a similar note.

If for example, there would only ever be 1 result, in this case 1 player (In my case the player number will be an order id). How could i extract only the order id from the following

<Order id="34343">
   <pricing currency="gbp">
    <price> 23.23 </price>
    </pricing>

</Order>

Edited by Reverend Jim: Fixed formatting

0

totally forgot id posted this.

I found a solution a few days ago.

If its a single element, something like <Orders><Order>13.45</Order></Orders> you would use $order = $xml->Orders->Order

If its got a few of them, like this <Orders><Order id="123" name="shoes"</Order></Orders> you would use $order = $xml->Orders->Order;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.