www.webdeveloper.com
Results 1 to 4 of 4

Thread: Random Script

  1. #1
    Join Date
    Nov 2004
    Location
    Little Britain
    Posts
    352

    Random Script

    I have a file which will be displayed on other websites using <?php require("file.txt"); ?>. I was wondering whether I could have each line of this randomised, so instead of line 1, line 2, line 3, appearing on other websites, I could have line 2, line 1, line 3.

    Cheers for your help

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    PHP Code:
    <?php
    $lines 
    file("file.txt");
    shuffle($lines);
    foreach(
    $lines as $line){
        echo 
    $line."\n";
    }
    ?>

  3. #3
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    quick and simple lol
    PHP Code:
    <?php
    $data 
    file('path/to/text.txt');
    shuffle($data);
    echo 
    implode(''$data);
    ?>

  4. #4
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Even more compact...
    PHP Code:
    <?php echo implode("\n"shuffle(file('path/to/text.txt'))); ?>
    Last edited by bokeh; 12-20-2005 at 11:44 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles