Page 2 of 2

Posted: Fri Dec 31, 2004 3:02 am
by carlmcdade
If you want to limit:

Code: Select all

<?php

foreach($OpenPlayList as $k => $v){
	    
	    if($k<200){ //if you want to make sure the file never get over 200 lines
		    $v = trim($v)."\n"; //nasty whitespace and carriage return bug in file()
		    fwrite($handle,$v);
	    }

	}
	fclose($handle);
?>
If you want to randomize the playlist:

Code: Select all

<?php

foreach($OpenPlayList as $k => $v){
	    
		$k = rand(0,200); //if you want to randomize the playlist
		$v = trim($v[$k])."\n"; //nasty whitespace and carriage return bug in file()
		fwrite($handle,$v);
	    }

	}
	fclose($handle);
?>

Posted: Fri Dec 31, 2004 4:14 am
by n00b Saibot
Dodge This (I mean try this He he he :P:P:P)

Code: Select all

<?php
    // Change this if you rename your playlist.txt file
    $file = "playlist.txt";
    
    // Get the contents of the current playlist file
  $plarr = file($file);
  if(count($plarr)>30)
  {
   $no_files_2_del = count($plarr)-30;
   for($i=$no_files_2_del;$i>0;$i--)
   array_pop($plarr);
   $handle = fopen($file,"w");
   foreach($plarr as $v)
   {fwrite($handle,$v);}
    fclose($handle);
   }
  else echo "File contains Entries less that or eqaul 30";
?>
I hope that works right 4 ya! ;-)

Posted: Sat Jan 01, 2005 6:59 pm
by SMR
Well it turns out that this worked for me.I added it to playlist_builder.php

Code: Select all

$PlayListLength = '30';
	$PlayListLength = ($PlayListLength - 1); // Account for the song about to be added
	$PlayListCount = file($PlayList);
	$OpenPlayList = fopen($PlayList, 'w');

	if (count(PlayListCount) < $PlayListLength) {
		unset($PlayListCount[$PlayListLength]);
	}

	$PlayListCount = implode('', $PlayListCount);

	fwrite($OpenPlayList, $PlaylistEntry . $PlayListCount);
	fclose($OpenPlayList);
Thanks for all the suggestions and help :D