Search multiple keywords from text file database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psaha
Forum Newbie
Posts: 16
Joined: Mon Oct 26, 2009 4:11 am

Search multiple keywords from text file database

Post by psaha »

Search multiple keywords from text file database

I have a text file database:
webdatabase.txt
------------------------------------------------------------------------------
1257143509||google web search||Enables users to search the Web, Usenet, and images||www.google.com->
1245876563||yahoo portal||free Yahoo! Mail & Instant messenger, news, finance||www.yahoo.com->
1254555967||MSN Live||Microsoft's portal, offering MSNBC News, search, sports, MSN Money||www.msn.com
------------------------------------------------------------------------------

The above text file database has column separator ||, and row separator as ->
The first column, generated from time() function, can be used as primary key.

I want to search several keyword(S) and the program will open
webdatabase.txt to search the keyword(S) from column1 and column2. Column0 and column3 need not to search.
Display the rows in DESC order. More occurrence to less occurrence.

Example: If anyone enter: web money
output will be:
1257143509||google web search||Enables users to search the Web, Usenet, and images||www.google.com
then
1254555967||MSN Live||Microsoft's portal, offering MSNBC News, search, sports, MSN Money||www.msn.com

(Without column separator)

Example 2: If anyone enter: Instant messenger portal
Display: 1245876563||yahoo portal||free Yahoo! Mail & Instant messenger, news, finance||www.yahoo.com
1254555967||MSN Live||Microsoft's portal, offering MSNBC News, search, sports, MSN Money||www.msn.com


-- Advance Thanks for your help

I have tried lots of code but getting 2 problems 1. Several keywords 2. Display the whole row in pagination format. I am not sending my php code yet as I want to see the different approach and concept.
- Thanks again and waiting for reply.

[Note: I promise, next time I will do in mysql database]
psaha
Forum Newbie
Posts: 16
Joined: Mon Oct 26, 2009 4:11 am

Re: Search multiple keywords from text file database

Post by psaha »

Still no reply!!
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Search multiple keywords from text file database

Post by McInfo »

Use SQLite. It's built into PHP. There is no server to install and the database is stored in a single file.

Creating an SQLite database is this easy:

Code: Select all

<?php
$db = sqlite_open('./database.sqlite');
sqlite_query($db, 'CREATE TABLE user (name VARCHAR(30), email VARCHAR(256))');
sqlite_query($db, 'INSERT INTO user (name, email) VALUES ("Tom", "tom@tom.tom")');
sqlite_query($db, 'INSERT INTO user (name, email) VALUES ("Sam", "sam@sam.sam")');
sqlite_close($db);
Retrieving records is this easy:

Code: Select all

<?php
$db = sqlite_open('./database.sqlite');
$result = sqlite_query($db, 'SELECT name, email FROM user');
foreach (sqlite_fetch_all($result) as $row) {
    printf('<p>%s: %s</p>', $row['name'], $row['email']);
}
sqlite_close($db);
Sorting and searching is handled with SQL queries. See SQLite SQL Syntax.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 1:31 pm, edited 1 time in total.
PM2008
Forum Newbie
Posts: 7
Joined: Mon Dec 29, 2008 10:47 am

Re: Search multiple keywords from text file database

Post by PM2008 »

For more comprehensive searches, you can use script http://www.biterscripting.com/helppages ... lStrs.html . It is for searching email files with multiple key words and key phrases, but any non-email files can be searched as well.


Also, take a look at http://www.biterscripting.com/LearningS ... sson5.html . It is a tutorial on how to develop scripts for searching files. Look at the scripts filesearch and emailsearch.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Search multiple keywords from text file database

Post by McInfo »

biterScripting is not PHP.

Edit: This post was recovered from search engine cache.
Post Reply