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

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
Still Learning
Forum Commoner
Posts: 25
Joined: Tue Jan 27, 2009 3:57 pm
Location: Philadelphia

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

Post 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?
Last edited by Still Learning on Wed Jan 28, 2009 8:59 am, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Still Learning
Forum Commoner
Posts: 25
Joined: Tue Jan 27, 2009 3:57 pm
Location: Philadelphia

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

Post 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:
Last edited by Still Learning on Wed Jan 28, 2009 10:34 am, edited 1 time in total.
Still Learning
Forum Commoner
Posts: 25
Joined: Tue Jan 27, 2009 3:57 pm
Location: Philadelphia

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

Post 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 !!!
Post Reply