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 guttyguppy on 03/06/06 06:11

<?php

I did this, and it works. I'm not sure why though, I worked at it for a
long time and got lucky. Can anyone tell me if they see anything
inherently wrong with it? It works so hey I'm not complaining...

$fp = fopen('filename.txt', 'r');
$random = rand() % 3663782;
fseek($fp, $random);
if (!fgets($fp)) {
$data=fgets($fp);
echo $data;
}
else {
echo fgets($fp);
}
?>

 

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

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