corillo181 Posted January 2, 2007 Share Posted January 2, 2007 i want everything someone goes inside my page a different song is on..how can i do that?[code]$dir="music/$song";$random=rand($dir);<embed src="$random" width="125" height="16"></embed>[/code]something like that? Link to comment https://forums.phpfreaks.com/topic/32510-random-question/ Share on other sites More sharing options...
JasonLewis Posted January 2, 2007 Share Posted January 2, 2007 well you could put all the files in the directory then do a random number between 0 and the [code=php:0]count($array);[code=php:0]then just do this:[code=php:0]$files = array("file1.wav","file2.wav"); //etc etc...$random = rand(0, count($files)); //i think you may need to subtract 1 off the count or make the first thing 1...echo <<<html<embed src="folder/{$files[$random]}" width="125" height="16"></embed>html;[/code] Link to comment https://forums.phpfreaks.com/topic/32510-random-question/#findComment-151135 Share on other sites More sharing options...
fert Posted January 2, 2007 Share Posted January 2, 2007 [code]$songs=array("dir/song.mp3","dir/song1.mp3","dir/song2.mp3","dir/song3.mp3","dir/song4.mp3");shuffle($songs);echo "<embed src=\"$songs[0]\" width=\"125\" height=\"16\"></embed>";[/code] Link to comment https://forums.phpfreaks.com/topic/32510-random-question/#findComment-151137 Share on other sites More sharing options...
JasonLewis Posted January 2, 2007 Share Posted January 2, 2007 that would work to fert, :) good one. Link to comment https://forums.phpfreaks.com/topic/32510-random-question/#findComment-151139 Share on other sites More sharing options...
corillo181 Posted January 2, 2007 Author Share Posted January 2, 2007 fert is there any way i can make the array search the whole folder becuase i have a lot of songs and it would be a lot of time to put each of them on the array manually. Link to comment https://forums.phpfreaks.com/topic/32510-random-question/#findComment-151142 Share on other sites More sharing options...
dcro2 Posted January 2, 2007 Share Posted January 2, 2007 If you have PHP 5, you can use scandir()[code]$dir = scandir("folder/");$rand = rand(0, count($dir)-1);$song = $dir[$rand];[/code] Link to comment https://forums.phpfreaks.com/topic/32510-random-question/#findComment-151145 Share on other sites More sharing options...
corillo181 Posted January 2, 2007 Author Share Posted January 2, 2007 sene like yahoo doesn't have php 5 becuase it doesn't work. Link to comment https://forums.phpfreaks.com/topic/32510-random-question/#findComment-151147 Share on other sites More sharing options...
kenrbnsn Posted January 2, 2007 Share Posted January 2, 2007 Use the [url=http://www.php.net/glob]glob()[/url] function.Ken Link to comment https://forums.phpfreaks.com/topic/32510-random-question/#findComment-151164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.