| 
	
 | 
 Posted by peter stickney on 02/27/07 08:53 
Excuse the babbling or lack of sense, it's been a long day. 
 
I am making a flat file, static HTML search engine for a site.  I 
downloaded a script from the net and have been working with it for my 
needs. 
 
Everything was working OK with a few test Lorem Ipsum pages.  But the 
moment I try to search real data, fit hits the shan. 
 
The script uses a regular expression to search through the files.  And 
for most of these files, the regular expression doesnt seem to pick up 
the matches as it should, and for lack of a match, it outputs the 
entire html page as a hit.  The search word is on the page somewhere, 
but it still outputs the entire page. 
 
Allow me 
--------8<---------------------------- 
                        if(preg_match_all("/((\s\S*){0,3})($keyword) 
((\s?\S*){0,3})/i", $portion, $match, PREG_SET_ORDER)); 
                        { 
                            if(!$limit_extracts) 
$number=count($match); 
                            else $number=$limit_extracts; 
 
                            for ($h=0;$h<$number;$h++){   // no limit 
                                    if (!empty($match[$h][3])) 
                                        $text = sprintf("... %s<font 
class='keyword'>%s</font>%s ...", $match[$h][1], $match[$h][3], 
$match[$h][4]); 
                                    else{ 
                                        //print_r($match); 
                                        } 
                            } 
                        } 
--------8<---------------------------- 
 
There's the regex that looks through $portion, which is the strip_tags 
version of the file's contents.  And if I echo $portion right before 
that line, I see the stripped code.  However, when I get to the line 
where it checks $match[$h][3] for the keyword that was searched for, 
it craps out.  Not 100% of the time, but most of the time.  Im trying 
to figure out details about these html pages, to no avail. 
So as a result of failing that empty test, the entire html page is 
dumped out as a search result. 
 
Not being a regex expert, Ive had a hell of time troubleshooting.  But 
I feel the problem lies in there. Something with the regex not finding 
the keyword correctly, or something. 
 
I hope this was clear enough for someone to point me in the right 
direction.  I'm gonna get some sleep and answer any questions anyone 
may have. 
 
Oh here's the URL 
http://www.bridgeportarena.com/search_test/form.php 
 
Search for "office", you'll get an idea of what I mean. 
 
Thanks 
 
-peter
 
  
Navigation:
[Reply to this message] 
 |