Edit: The title is confusing because I wrote it with a different idea in mine and forgot to change it :S.
Basically I have this PHP which takes a text file and outputs a random 8 lines from it. Now this is fine, except sometimes you get repeats which I do not want. I figure it will be complicated to take the code that I have and modify it so that it has no repeats.
What I want to do is make it shuffle the lines in the text file and then output the top 8 or something.
What I have:
PHP Code:<?php
function RandomLine($seed) {
$sites = file('/dir/to/file.txt');
$string = $sites[array_rand($sites)];
return $string;
}
$s0 = RandomLine(rand((float) microtime(), 1000003));
$s1 = RandomLine(rand((float) microtime(), 1000003));
$s2 = RandomLine(rand((float) microtime(), 1000003));
$s3 = RandomLine(rand((float) microtime(), 1000003));
$s4 = RandomLine(rand((float) microtime(), 1000003));
$s5 = RandomLine(rand((float) microtime(), 1000003));
$s6 = RandomLine(rand((float) microtime(), 1000003));
$s7 = RandomLine(rand((float) microtime(), 1000003));
$link = array($s0, $s1, $s2, $s3, $s4, $s5, $s7, $s7);
shuffle($link);
foreach ($link as $value)
{
$explode = explode('|', $value);
echo '<p>' . $explode[2] . ' <a href="' . $explode[0] . '">' . $explode[1] . '</a> ' . $explode[2] . '</p>';
}
?>
I want to take /dir/to/file.txt, shuffle it and feed the top 8 lines or whatever into my explode.





Reply With Quote


