Results 1 to 5 of 5

Thread: getting a random item from .txt file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    getting a random item from .txt file

    does anyone know how to get a random item from a .txt file in php?

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: getting a random item from .txt file

    how is the text file delimited?

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: getting a random item from .txt file

    And what kind of item do you want to get?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4
    Junior Member
    Join Date
    Oct 2005
    Posts
    17

    Re: getting a random item from .txt file

    look at the fopen() and fgets() functions on php.net

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: getting a random item from .txt file

    <?
    for ($i = 1; $i <= 200; $i++)
    {
    $textfile ="file.txt";
    $items = file("$textfile");
    $item = rand(0, sizeof($items)-1);
    $numbers[$i] = $items[$item];
    }
    ?>

    will this code take 200 RANDOM keywords each time from file.txt? file.txt has over 5000+ words. so what i wanted to do was grab 200 random keywords from that 5000 words each time the page is loaded

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width