Forum Moderators: coopster

Message Too Old, No Replies

How to order LI lines at webpage if there is number within TXT line?

         

toplisek

10:24 pm on Dec 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have exploded values from TXT file.
How to sort LI line according to number within TXT file? See sample 7.
I like to show first 50 records and just records 5 to 10.

Structure of TXT file is like:
15.03.201004:54:347Searchterm1
.
.
.

Code is like:
<?php

$file = file_get_contents('search_terms1.txt');
$lines = explode("\n", $file);
ob_start();
foreach($lines as $line_number => $line) {

if ($line_number >= 50) break;
echo '<li class="tag1"><a href="#">' . array_pop(explode("\t", $line)) . "</a></li>\n";

}
ob_end_flush();
?>

coopster

8:47 pm on Dec 27, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You will either have to create a new array by looping through the exploded array results as you have started here, or parse each line using something like fgetcsv first. Either way, you'll need to have access to that integer "index" number for sorting purposes.