: : How would you pick a random piece of text from a text file and store it in a variable?
: This is how I would do it... roughly.
: Let's say that the file looks like this:
: $fopened = fopen(file, r); //Open the file... just for reading.
: $string = fread(fopened); //Read it into a string.
: $exploded = explode("/r/n", $string); //Separate it by newline into an array.
: $rand = rand(0, count($exploded)); //Randomize a number between 0 and the number of elements of the array.
: echo "The random word is:/n". $exploded[$rand]; // Echo element $rand of array $exploded
: fclose(file); //Close it.
: That's how I would do it. It would either echo "foo" or "bar." Now, if you wanted to separate the words by spaces, not new lines, you would just change the "/r/n" to " ".
makes sense to me, only one problem - i dont know how to tell it *what* file to open :P