Jump to content

Random Script


spfoonnewb

Recommended Posts

Hi,

So I have this random script.. it works.

What I want it to do is to select 10 files in a directory, (Or select 10 strings in an array on the same page), and display them, but they cannot repeat.. Possible?

[code]<?php

$txt_array = Array();
$my_dir = "includes/";  //Replace it with your frase's directory (dont'n delete the slash)
if ($dir = @opendir("$my_dir")) {

  while (($file = readdir($dir)) !== false) {
  if ($file != "." && $file != ".."  && !is_dir($my_dir.$file))
  {
  /* echo $my_dir.$file."<br>";  DEBUG show file list */
  $txt_array[] = $file;
 
  }
  } 
  closedir($dir);
}

$random_number=rand(0, count($txt_array)-1);
$random_txt=$txt_array[$random_number];

include($my_dir.$random_txt);

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/31666-random-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.