|
Prev: Shared Authentication Scheme - the reason for the Redirect andPOST mailing
Next: Freelance PHP development in India
From: Sudhakar on 13 Jul 2008 12:17 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.
From: Robert Cummings on 13 Jul 2008 12:28 On Sun, 2008-07-13 at 21:47 +0530, Sudhakar wrote: > 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. I don't suggest using file_get_contents. It would probably be more efficient (at least less memory intensive) to use fopen() and fread(). Just be sure you overlap each read by $the_size_of_the_largest phrase_or_keyword - 1. Then use stripos() for matching... of course that won't work so well if whitespace doesn't need to match exactly in phrases. In which case you'll need to resort to other techniques. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP
From: dg on 13 Jul 2008 13:10
On Jul 13, 2008, at 9:17 AM, Sudhakar wrote: > 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. I use this script to list archive files from a directory based on keyword. I'd guess a modified version using the keywords from users might work: // create archives box if ($handle = opendir('../diaryarchives/')) { while (false !== ($file = readdir($handle))) { $pos = strpos($file, diary_); $pagemarked = "diary"."_"; if ($pos !== false) { //print "$file<br>"; $file_name = ereg_replace ("$pagemarked","",$file); $file_name = ereg_replace (".php","",$file_name); //print "* $file_name<br>"; //print "$file<br>"; $archive_list_gather[] = '<li><a href="/diaryarchives/'. $file.'">'.$file_name.'</a></li>'; } } closedir($handle); } rsort($archive_list_gather); foreach($archive_list_gather as $value) { $archive_list .= "$value"; } // build archives box $archives_box = '<div id="diary-archives"> <h3 class="side"><img src="/images/h3s_diaryarchives.gif" alt="Diary Archives" width="225" height="20" /></h3> <ul> '.$archive_list.' </ul> </div>'; // publish archives box $filename = PATHA.'/diaryarchivesbox.php'; publishpages($archives_box, $filename); |