SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have a JavaScript code which is currently used for randomly displaying certain items.

    I wish to convert that to PHP now.
    How do I go about it?

    Thanks
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are the random items images, quotes?

    Normally the easiest way to display say a random image for directory would be

    $dir = dir("pathto/imagesdir");
    while($file = $dir->read()) {
    if (($file != ".") && ($file != "..")) {
    $files[] = $file;
    }
    }

    srand((double)microtime()*1000000);
    $randval = rand (0,(count($files)-1));
    printf('<img src="pathtoimages/%s">', $files[$randval]);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm..COOL!
    Thanks..

    I managed to come up with a function previous..but it couldn't work..well, I've fixed it.
    Here's the code

    function randomline($filename) {
    $file = file($filename);
    srand((double)microtime()*1000000);
    while ($random == "") {
    $random = ereg_replace("\n","",$file[rand(0,count($file))]);
    }
    echo $random;
    }
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


Bookmarks

Posting Permissions

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