Jump to content


Approach to searching, insertion and deletion using text files

  • Please log in to reply
1 reply to this topic

#1 sendoh07

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 September 2006 - 05:45 PM

Hi all. If I have to read from a text file, and do a query to display all usernames. How can I do it from reading a text file? Please note that as much as I would to use MySQL, I am not allowed to. For example, the text file "test.txt" contains the following:
M0001:jlee:James:Lee:23:Lakers Avenue 111/03 Country:123-345678
M0002:tbogard:Terry:Bogard:23:Lakers Avenue 211/03 Country:124-333678
The format is memberID:username:first name:last name:age:address:phone

In normal mysql queries you would just have to do something like "SELECT username FROM Users" to display all the usernames. However, now that I am using just a text file, how can I do searching, insertion and deletion?

Currently, I can only think of tokenizing those data and storing them into an array or linked-list. However, this approach is not that efficient.

Can anyone point me in a right direction please? Thanks!

#2 Kris

  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 04 September 2006 - 11:07 AM

I would have thought you'd have to dump it all into an array and sort through it.
//Display usernames
$content = file("test.txt");
foreach($content as $line) {
    $fields = explode(":",$line);
    echo $fields[1]."<br/>";

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users