MrGaz Posted February 3, 2008 Share Posted February 3, 2008 Hi I'm new to PHP and so am unfamiliar about all the pros/cons of the many different methods of reading files. I'm looking for a function that will allow me to quickly read a single line at random from a very large text file. The text file will just be a very long list of words, with each word on a new line, I want to be able to pick one of these words at random. The text file will also be local on my server and not a url. Anyone able to help with the best solution? Cheers Gaz Quote Link to comment https://forums.phpfreaks.com/topic/89204-solved-reading-a-random-line-from-a-text-file/ Share on other sites More sharing options...
trq Posted February 3, 2008 Share Posted February 3, 2008 <?php $file = file('thefile.txt'); echo $file[rand(0,count($file)-1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89204-solved-reading-a-random-line-from-a-text-file/#findComment-456755 Share on other sites More sharing options...
MrGaz Posted February 3, 2008 Author Share Posted February 3, 2008 Brilliant, thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/89204-solved-reading-a-random-line-from-a-text-file/#findComment-456764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.