Web Hosting Forum | Lunarpages

Author Topic: Randomly Shuffle a text file???  (Read 4675 times)

Offline p0tter

  • Village Idiot
  • Quantum Encyclopedia Writer
  • *****
  • Posts: 3084
    • My Pixel Addiction
Randomly Shuffle a text file???
« on: September 10, 2005, 02:46:26 AM »
Didn't know where else to put this. I have a text file with 176 lines of text. I need the lines of text shuffled into a random order. Doesn't really matter to me how it gets done. Just so long as I can either input text into a field and have it shuffle it. Or have a script/program shuffle the text file.
O|||||O

Offline JamesG

  • Web Designer UK
  • Berserker Poster
  • *****
  • Posts: 11732
  • Web Designer
    • Affordable Web Design
Re: Randomly Shuffle a text file???
« Reply #1 on: September 10, 2005, 05:31:23 AM »
i dont understand what you mean p0tter?

i have a small php script that used to randomly pull random quotes from a text file, each line was a new quote, would that help?

+ where have you been of late?

Offline Nibbler

  • 21st century digital boy
  • Master Jedi
  • *****
  • Posts: 1168
    • Coppermine
Re: Randomly Shuffle a text file???
« Reply #2 on: September 10, 2005, 10:30:45 AM »
Code: [Select]
$data = file('file.txt');
shuffle($data);
$newdata = implode("", $data);
$fp = fopen('file.txt', 'w');
fwrite($fp, $newdata);
fclose($fp);

Make sure there is a new line at the end of the input file.
Missing since 1983


Offline p0tter

  • Village Idiot
  • Quantum Encyclopedia Writer
  • *****
  • Posts: 3084
    • My Pixel Addiction
Re: Randomly Shuffle a text file???
« Reply #3 on: September 10, 2005, 02:16:14 PM »
Code: [Select]
$data = file('file.txt');
shuffle($data);
$newdata = implode("", $data);
$fp = fopen('file.txt', 'w');
fwrite($fp, $newdata);
fclose($fp);

Make sure there is a new line at the end of the input file.

Thanks man. Worked perfectly.

+ where have you been of late?

Just busy busy busy. :)
O|||||O

 

Share |