Page 1 of 1

Going crazy.. i know my problem has got to be simple.

Posted: Tue Jan 27, 2009 4:06 pm
by Still Learning
But I can't figure out what it is......
Basically I have xspf playlists stored on my server, and I want to be able to read them so I can extract individual pieces of info from them, and eventually allow others to make changes to the playlist themselves(like change the order of songs).

I'm trying to write a basic function right now basically just outputting the number of tracks an artist has, and all the info from one of them.
This is the error message I get:
Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to allocate 5084 bytes) in /home/wants0/public_html/wp-includes/functions.php on line 2432
I tried upping the memory in the php.ini file a couple of times, as you can see by the huge allowed mem. size, but that didn't work. Besides there's no reason why it should be taking up so much memory. Btw LINE 2432 is line 19 in here.....

Code: Select all

function get_playlist_info($theartname)
{
 
$numberoftracks= 0;
 
 
$xspfname= $theartname . ".xspf";
$pl = fopen($xspfname, "r");
$size= filesize($xspfname);
$data= fread($pl, $size);
$endoftracklist = stripos($data, "</tracklist>");
fseek($pl,0);
$beginningoflist= stripos($data, "<track>");
fseek($pl,0);
$currentlocation= 0;
while ($currentlocation<=$endoftracklist)
{
 
$trackpos= stripos($data, "<track>");
fseek($pl, $trackpos);
$endtrackpos= stripos($data, "</track>");
$trackinfo[$numberoftracks]= fread($pl, $endtrackpos);
$numberoftracks++;
$currentlocation= $beginningoflist+ $trackpos+ $endtrackpos;
fseek($pl,$currentlocation);
 
} //while not end of file
fclose($pl);
echo $theartname . " has " . $numberoftracks . " tracks";
echo "<BR><BR>";
echo $trackinfo[1];
 
} //end of function get_playlist_info
Any ideas?

Re: Going crazy.. i know my problem has got to be simple.

Posted: Tue Jan 27, 2009 5:19 pm
by pickle
Without looking at it too closely, I can tell you you're doing WAY too much work. XSPF is XML - so why not use SimpleXML an XML library to parse it. It'll make life MUCH easier & your script MUCH more efficient.

Re: Going crazy.. i know my problem has got to be simple.

Posted: Wed Jan 28, 2009 6:59 am
by Still Learning
Yeah, I know xspf stands for XML Sharable Playlist File, but I have no idea how to use Simple XML and XML Libraries. I know what the playlists need to look like to work for the xspf player, but that's about it. Guess maybe I'll do some research on XML.

Thanks for the response.

Ps. Doh!!! Just did some research and you're totally right. Now it's just more stuff to learn. Just learned some basics of actionscript so I could edit my flash player, php, java and html all in the last couple months. Now I need to learn xml. :banghead:

Re: Going crazy.. i know my problem has got to be simple.

Posted: Wed Jan 28, 2009 9:37 am
by Still Learning
Wow.... thank you so much for the XML suggestion about parsing, etc....

The same place that I learned most of my php for free, http://www.w3schools.com/PHP/DEfaULT.asP, also has tutorials on XML. Already made a separate hidden webpage that parses the info from the playlists. You were right it's much more efficient, and now I can easily write functions to read and/or change the info in each playlist.

You rock pickel !!!