Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Shuffle() Issue

$
0
0

Hi in my code below, echo $body; outputs the link to every song in my $SongsFolder. How can I make it echo only one link and that link is the song the $Shuffle chose? I know I have array but is there a way to get around it? Anything I should change up?

<?php
function fooFucker($url) {
$a = join('/', array_map('urlencode', explode('/', 
$url)));
return str_replace('+', '%20', $a);
}

$SongsFolder = "songs";

header("Content-Type: audio/x-mpegurl");

$body = '';

$Songs = glob($SongsFolder."/*.mp3");
shuffle($Songs);
$first = 0;

foreach($Songs as $Song)
{
$SongPath = pathinfo($Song);
if ($first != 0) {
$body .= "\n";
}
$first = 1;
$body .= 
"http://".$_SERVER['HTTP_HOST'].fooFucker(dirname($_SERVER['PHP_SELF']))."/".fooFucker($SongsFolder)."/".fooFucker($SongPath['basename']);
}
header('Content-Length: ' . strlen($body));
echo $body;
?>

Viewing all articles
Browse latest Browse all 13200

Trending Articles