Regular Expression Detecting Entire Page

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

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

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
((\s?\S*))/i", $portion, $match, PREG_SET_ORDER));
                            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],

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

Search for "office", you'll get an idea of what I mean.



Site Timeline