faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 12 people (67%) answered Yes
Recently 5 of 9 people (56%) answered Yes

Entry

How cam I sort the contents of a file using PHP?

Aug 5th, 1999 11:49
Paul DuBois, Nathan Wallace,


You could use a system call:

    exec("sort -o db.txt db.txt");

or you can do the whole thing in PHP using:

    $db = file("db.txt");
    sort($db);
    $dbh = fopen("db.txt","w") || die("couldn't open");
    fwrite($dbh,implode($db,"\n");

Probably what you really want though is a database, especially if the
files will be large.