[PHP] counting files, choosing at random

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re: [PHP] counting files, choosing at random

    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);

    David Otton Guest

  2. Similar Questions and Discussions

    1. Illustrator10 Imports PSD files at Random%'s...Looks fine..
      HI, I have recently switched form Illustrator 8 to 10, and also upgraded to system 10(I am also on a G4). When I place a psd file in Illustrator 10,...
    2. Using Math.random to go to random frames
      Hello everyone. My cerebral density is preventing me from seeing the solution to this problem. I have the following code which causes the user to...
    3. Counting files
      Hi, I have a list: file1 file2 dir1/file3 dir1/file4 dir1/subdir1/file5 dir2/file6
    4. counting files, choosing at random
      i think the problem is there is a newline between the "<img src="/szukaj/images/i" and "<? ". try write them in the same line may be a...
    5. RANDOM INCLUDE FILES
      Trying to randomize display of collection of include files. e.g. <!--#include virtual="/include/nav/footer/navy_blue_footer.inc"--> but can't seem to...
  3. #2

    Default Re: [PHP] counting files, choosing at random

    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
    [url]http://hyperreal.info[/url] / ALinkA / bOrk! * WiNoNa ) (
    [url]http://szatanowskie-ladacznice.0-700.pl[/url] foReVeR( * )
    Poznaj jej zwiewne kształty... [url]http://www.opera.com[/url] 007

    Adam I Agnieszka Gasiorowski Fnord Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139