You are here: Re: Select a random line from a text file « All PHP « IT news, forums, messages
Re: Select a random line from a text file

Posted by Johannes Wienke on 09/28/08 11:41

Am 04.03.2006 19:45 schrieb guttyguppy@gmail.com:
> I know that file('mytext.txt'); will return an array of all the lines
> of text in mytext.txt. What I want is to grab the text from random line
> in mytext.txt.
>
> $lines = file('words.txt');
> $random = rand() % 100;
> echo "line=" . $lines[$random];
>
> The problem is I have a very long text file, and each time the php page
> is loaded there is a delay as it needs to assemble the enormous array.

Depending on your server-config it is perhaps faster to use
unix-commands like cat in combination with head and tail. If the server
allows this, you can use them with exec(). Maybe it is worth a try.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация