I am trying to read, shuffle, and then display the contents of a text file. The text file contains a list of codes (each in a new line - without commas, etc.).
1490
1491
1727
364
466
783
784
786
My code is:
$file = fopen("keywords.txt", "r");
shuffle($file);
while (!feof($file)) {
echo "new featuredProduct('', ". "'". urlencode(trim(fgets($file))) ."')" . "," . "\n<br />";
}
fclose($file);
The result is the following:
new featuredProduct('', '1490'),
new featuredProduct('', '1491'),
new featuredProduct('', '1727'),
new featuredProduct('', '364'),
new featuredProduct('', '466'),
new featuredProduct('', '783'),
new featuredProduct('', '784'),
new featuredProduct('', '786'),
I figured that I would need to shuffle the contents of the variable $filebefore going through and displaying, and as you can see, the shuffle function doesn’t work or didn’t I use it correctly?
I expected the list to be ordered in a much more random manner.