By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,452 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,452 IT Pros & Developers. It's quick & easy.

Sorting text file content

P: 1
Hello friends, i'm writing search page for my local website. i'm storing all file list in text file. And also adding a value to each line at the beginning. now i want to sort file content in descending order according to begin value.

Text File having list like this:

5|<h3><a href='http://localhost/rchiving-tagging/archiving

2|<h3><a href='http://localhost/rchiving-tagging/archiving

3|<h3><a href='http://localhost/rchiving-tagging/archiving

4|<h3><a href='http://localhost/rchiving-tagging/archiving

can anyone help it plz?
Oct 4 '11 #1
Share this Question
Share on Google+
1 Reply

P: 638
Hi Shiavarj rh,

create the file object

read the contents of the file

split them into an array (explode()) on the condition of line break i.e. \n

sort the array(array_sort())

reverse the array (use array_reverse())

then re-join the array use implode() function (so that you can

join them on to a condition i.e. \n)

rewrite the file

hope that helps,
Omer Aslam
Oct 4 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.