Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 10:54:59 AM

Pages: [1]   Go Down
  Print  
Author Topic: Randomly Shuffle a text file???  (Read 2447 times)
p0tter
Village Idiot
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3158


WWW
« on: September 10, 2005, 03: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.
Logged

O|||||O
JamesG
Web Designer UK
Berserker Poster
*****
Offline Offline

Posts: 12038


Web Designer


WWW
« Reply #1 on: September 10, 2005, 06: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?
Logged

Nibbler
21st century digital boy
Master Jedi
*****
Offline Offline

Posts: 1178



WWW
« Reply #2 on: September 10, 2005, 11:30:45 AM »

Code:
$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.
Logged

Missing since 1983

p0tter
Village Idiot
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3158


WWW
« Reply #3 on: September 10, 2005, 03:16:14 PM »

Code:
$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. Smile
Logged

O|||||O
Pages: [1]   Go Up
  Print  
 
Jump to: