#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    1
    Rep Power
    0
    Hey,

    I got a text file that has 2 lines:

    Random 1
    Random 2

    What I am trying to find out is how do I make php randomly pick one of those 2 lines or more say I have more in the future from this txt file named random.txt. I tried looking in the manual but it didn't help me really.
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    srand();
    $lines = file("random.txt");
    $random_key = array_rand($lines,1);
    echo "Random Line: " . $lines[$random_key];
    [/code]

    That should do it...

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************

IMN logo majestic logo threadwatch logo seochat tools logo