Read the content of the file randomly
Posted: Sat Oct 27, 2007 8:39 am
How can I read the content of the file(i.e,the sentences of a text file) randomly?

A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$text = file_get_contents('my_text_file.txt');
$sentences = explode('.', $text);
echo trim($sentences[array_rand($sentences)]);Code: Select all
<?php
$sentences = explode("\n", file_get_contents('file.txt'));
shuffle($sentences);
echo '<pre>';
print_r($sentences);
echo '</pre>';