Jump to content

Approach to searching, insertion and deletion using text files


sendoh07

Recommended Posts

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:
[code]M0001:jlee:James:Lee:23:Lakers Avenue 111/03 Country:123-345678
M0002:tbogard:Terry:Bogard:23:Lakers Avenue 211/03 Country:124-333678
etc.....
[/code]
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!
Link to comment
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.