Jump to content

sorting a textfile


phpllama

Recommended Posts

if you want to see a working example:

<?php
$file = "yourfile.txt"; //declare your file name here
$fh = fopen($file, "r"); // this opens the text file in read-only
$data = fread($fh, filesize($file)); // this takes all the data in the file, and puts it into a variable
fclose($fh); //and we close the file
$data_array = explode("\n", $data); //we separate each line into an array
$end = count($data_array) - 1; // we find the end of the array
$rand = rand(0,$end); // we randomly pick a line in the array
$rand_s = explode(",", $data_array[$rand]); //we separate all data from the selected item, based on the ","
print "({$rand_s[0]},{$rand_s[1]})"; // we now have the data.
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/167356-sorting-a-textfile/#findComment-882482
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.