Re: counting files, choosing at random

From: Date: Wed, 13 Aug 2003 11:48:55 +0000
Subject: Re: counting files, choosing at random
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-159421@lists.php.net to get a copy of this message
David Otton wrote: > On Wed, 13 Aug 2003 10:54:58 +0200, you wrote: > > > > > I want to choose a file at random from a > > directory which adheres to certain naming scheme. > > I can't get it to work. It's probably something > > simple...Here is a relevant snippet: > > > ><img src="/szukaj/images/i > ><? > >chdir('./szukaj/images/'); > >echo mt_rand(0, count(glob('i*.gif', GLOB_NOSORT)) - 1); > >?> > > Wrapping the glob() in the count() is just throwing away the filenames. Try > something more like this. > > $names = glob('i*.gif', GLOB_NOSORT); > if (sizeof ($names)) > { > $offset = mt_rand (0, sizeof ($names)); > $name = $names[$offset]; > } else { > $name = 'not found'; > } > echo ($name); Thank you, it solved my problem (after minor tweaking). This list is just so great! :8]. -- Seks, seksić, seksolatki... news:pl.soc.seks.moderowana http://hyperreal.info / ALinkA / bOrk! * WiNoNa ) ( http://szatanowskie-ladacznice.0-700.pl foReVeR( * ) Poznaj jej zwiewne kształty... http://www.opera.com 007

« previous php.general (#159421) next »