Edit
by Michael Wassil - 10 years ago (2015-02-10)
Need to sort by columun a tab delimited text file
| I need to read a tab delimited text file, display it as a table sorted by columns |
Ask clarification
1 Recommendation
MySQL Database Library: Access MySQL databases and manipulate files
This class can access MySQL databases and execute common queries. Currently it can:
- Connect to a given MySQL host and access a given database
- List all tables in the accessible databases
- Get the columns of a given table
- Compose and execute SELECT queries to a given table getting specific fields by a given sorting order returning the results into a single array
- Search for given table records that match given conditions
- Insert table records with given field values
- Update table records with given field values and conditions
- Delete table records that match a condition
- Create table records for a new user with a password
- Authenticate a given user with a password in the users table
- Change a given user password in the users table
- Update or delete given user records in the users table
- Read the text contents of files in the format CSV, PDF or Microsoft Word
- Write plain text or CSV files
- Rename or delete files
- Get the list of files from a directory
- Etc..
| by Justin Eldracher package author 160 - 9 years ago (2015-06-22) Comment
The read() method in my class will read a tab/comma delimited file into a matrix, doesn't have a built in sorting feature, though. The method defaults to csv, but if you change the $_csvdelim_ variable, or include the customer delimiter as the third parameter, you can read any type of delimited file. So for example, you would need these three lines:
include "DB.php";
$db = new DB();
print_r($db->read("delimited.txt", "csv", "\t"));
The second parameter must be "csv" so the method knows it's dealing with delimited text.
Hope that helps. |