PHP snippets

From Helpful

'Pick random filename from directory'

E.g. for 'display random image', like the code below does. Probably a lot more IO-intensive than you want.

#Am seeding. Am being randomly picky.
list($usec, $sec) = explode(' ', microtime());
srand( (float) $sec + ((float) $usec * 100000) );

#dir names -> array
$images=scandir('img/logos');
$images=array_slice($images,2);  #slice out . and ..
$image=$images[rand(0,count($images)-1)]; #pick one (could also use array_rand())
print "<img src=\"img/logos/$image\">";