Lets say Ive got a text file which has got 10000 paragraphs in it each seperated by a blank line.
How can I have a script which randomly selects 200 of those paragraphs and puts it into a variable? Each time the script is reloaded the script should select different paragraphs...
Comments
First, you'll have to count how many paragraphs there are by using substr_count. Then make a loop that'll go around 200 times (for each one you want), and gets a random number between 1 and the integer returned from substr_count.
Then you'll have a random number that'll be used to represent which paragraph of the 10,000 you want to get. You can then use various string functions (getting the position of each blank line with strpos) until you get to the part you need, and using more string functions (like substr) you can extract it.
Webmaster-Talk.com
Chroder.com
The Royal Ram
If it needed to be fast and light, you should either 1) read the file in maybe 1024 byte increments (getting the paragraphs as you go along) or 2) store the paragraphs separately somehow (perhaps in a database)
Webmaster-Talk.com
Chroder.com
The Royal Ram