FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


string comparison





susapra
hi

i am writing a small application where a user enters a phrase in the textfield and i would like to display all the files present in the root directory which consists of the keyword or keywords entered by the user.

i have used a few comparison functions but i am not getting the expected result.

$my_file = file_get_contents("filename.html");
what ever the user enters whether it is a single word or few words i would like to compare with $my_file in a case insensitive manner.

can anyone suggest the best method and how to go about.

thanks.
rvec
To check if a word is used in the file use stristr().

you can make an array of the files and in the foreach loop check if the word is in that file. If the files aren't too big that should work.
kv
Actually, it is resource intensive to read all files each time you search for keywords. A better way is to write a script which will index a filename against the words it contains in a database. You will have to run this script once in a while to rebuild index. When searching for the files, instead of reading file, just search for keywords (and the related filename) from the database.

BTW, this is the way most of the search engines work.
rvec
depends on how big the files are, how many there are, how often they are changed and how often they need to be searched. If they are dynamic and one search is done each day it's easier to directly search the scripts.

If the files stay the same for over 10 searches or if the updates don't change a lot to the files kv's suggestion is better.
phucngo
kv wrote:
Actually, it is resource intensive to read all files each time you search for keywords. A better way is to write a script which will index a filename against the words it contains in a database. You will have to run this script once in a while to rebuild index. When searching for the files, instead of reading file, just search for keywords (and the related filename) from the database.

BTW, this is the way most of the search engines work.

Using mnoGoSearch search engine may be a chosen solution.
PHP Manual - XCI. mnoGoSearch Functions wrote:
mnoGoSearch is a full-featured search engine software for intranet and internet servers, distributed under the GNU license. mnoGoSearch has a number of unique features, which makes it appropriate for a wide range of applications from search within your site to a specialized search system such as cooking recipes or newspaper search, FTP archive search, news articles search, etc.

More information about mnoGoSearch can be found at http://www.mnogosearch.org
Related topics
writing COM components in Perl
Turkey Bird flu Spreads
C++ Assignment! its about string.h
Disabling "This is a string with a $var"?
Anybody else here a little peeved off?
A debate of religion, science, and more
Black Holes Actually Green
string's theory!!
replace a string for a position of text
Replacement of hexadecimal values in PHP string
php..free account help
String theory
Interesting Concept used by SEOs
Email Validation
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.