# Random File list with PHP

**URL:** <https://forum.kirupa.com/t/random-file-list-with-php/208542>\
**Category:** programming\
**Created:** [November 29, 2006, 9:28pm UTC](https://forum.kirupa.com/t/random-file-list-with-php/208542 "2006-11-29T21:28:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonahholliday](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jonahholliday/32/2097_2.png) [@jonahholliday](https://forum.kirupa.com/u/jonahholliday)\
**Post date:** [November 29, 2006, 9:28pm UTC](https://forum.kirupa.com/t/random-file-list-with-php/208542/1 "2006-11-29T21:28:01Z")

</div>

Hi,

I have been scratching my head trying to figure this out… sadly I haven’t. I’m sure this is something simple; please help me out.

using PHP I would like to list all the files in a specified folder in a random sequence. And output this as an xml file. Here’s what I have so far…

```auto
<?
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
";

echo "<songs>
";
/////////////////////////////////////////////////////////////////////////////////////
			
$file_dir="mp3";
////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////

$dir=opendir($file_dir);
	while ($file=readdir($dir))
	{
		if ($file != "." && $file != "..")
		
		{
			list($name, $ext) = explode(".", $file);
			list($artist, $title) = explode("-", $name);
			
			echo "<song path=\"".$file."\" artist=\"".$artist."\" title= \"".$title."\"></song>
 ";
			
		}
	}

echo "</songs>
";
?>

```

How can I modify this to generate a random list.

Thanks!
