Select Fread() select a line by random ??

Discussion in 'PHP' started by cornetofreak, Jun 5, 2008.

  1. #1
    hey ppl ive got a text file with over 500 web addresses, each on there own line between the <loc>http://..........</loc> etc

    i have a parser that takes one of these links and takes html content out of them

    i wont to open the document secect a random line and import it as a variable

    please help
     
    cornetofreak, Jun 5, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    just look up how to read a certain line in a php file, then make a variable with math random between x and y, so it generates the random number, then plug it into the file read code so it reads that line
     
    crath, Jun 5, 2008 IP
  3. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <?php
    
    $file = file_get_contents('addresses.txt');
    $array = explode("\n", $file);
    
    $random = rand(0, count($array));
    $url = $array[$random];
    
    
    
    echo $url;
    ?>
    
    PHP:
    Hope it helps :)
     
    lui2603, Jun 6, 2008 IP