Winamp's Now Playing Plugin: Need help with advanced array.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Winamp's Now Playing Plugin: Need help with advanced array.

Post by JAB Creations »

The Now Playing plugin is configured to send an array of data to a file on my website via $_POST request.

Here is what that data's structure looks like...
http://users.jyu.fi/~ltnevala/nowplayin ... parameters

I'm a little bit baffled as how to access any part of this array...or subarrays. Could someone please fill me in on what their array setup is referred to as so I could do a little reading?

In essence I'd like to assign a song name to a variable. If I know how to do that I would know how to work with this sort of array just fine.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Winamp's Now Playing Plugin: Need help with advanced array.

Post by JAB Creations »

Ah never mind, I did not spot their example...associative array?

I'll post my script once it's finished. :mrgreen:
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Winamp's Now Playing Plugin: Need help with advanced array.

Post by JAB Creations »

If I change the fopen mode from x to w it writes to the file...but I don't want to clear the file's contents! It does nothing when using x but it's the only mode listed on php.net that does not delete the contents and writes to the file at the beginning. Suggestions?

Code: Select all

<?php
$fp = fopen('winamp.txt', 'x');
 
for($i = 0; $i < count($_POST['Song']);$i++)
{
 $artist = $_POST["Song"][$i]["Artist"];
 $album = $_POST["Song"][$i]["Album"];
 $title = $_POST["Song"][$i]["Title"];
 
$update = $artist.' - '.$album.' - '.$title."\n";
 
 fwrite($fp, $update);
}
 
fclose($fp);
?>
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Winamp's Now Playing Plugin: Need help with advanced array.

Post by JAB Creations »

Well I've confirmed that the file isn't being opened even though it has a CHMOD of 777 (I usually only do 646 though but this is testing)...

Code: Select all

<?php
function file_error()
{
 $fp = fopen('winamp.txt', 'w');
 $update_now = fwrite($fp, "an error ocurred!");
 fclose($fp);
}
 
$fp = fopen('winamp.txt', 'x+');
if (!$update_now) {file_error();}
 
for($i = 0; $i < count($_POST['Song']);$i++)
{
 $artist = $_POST["Song"][$i]["Artist"];
 $album = $_POST["Song"][$i]["Album"];
 $title = $_POST["Song"][$i]["Title"];
 $update = $artist.' - '.$album.' - '.$title."\n";
 $update_now = fwrite($fp, $update);
}
 
fclose($fp);
?>
Post Reply