I am having a bit of a hard time thinking about what to do for this. I would like to display a random line from a specific text file, then after it displays it will remove that line from the text file so it will no longer show up when page refreshed.
$lines = file('');
echo $lines[array_rand($lines)];
file
read lines into array. array_rand
to get a random key from the array of lines. unset
to remove an element. file_put_contents
to write back to file.
$filename = 'filename.txt';
$lines = file($filename);
$r = array_rand($lines);
echo $lines[$r];
unset($lines[$r]);
file_put_contents($filename, implode("", $lines));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments