Get a Quote
November 9, 2010

Site Search Without a Database

One of the things I have been working on recently was a search engine script for one of our clients.

Originally I figured that I would easily find a script that would do exactly what I wanted, though I did find many amazing and powerful scripts I was restricted by the fact that this particular project did not have a database to work with and set up a database for searching through such a small project was just not necessary. So instead I found a much weaker script which searched a single directory for file names matching the search query, this was useful because from there I was able to expand its capability.

Regular Expressions to the Rescue

I would like to mention that there are multiple ways to do the search, XML parsers are an option but in my case, I used regular expressions.

I mentioned earlier in the post that the original script I found only checked filenames in one directory so I changed it to search the file contents instead.

This is a snippet of code I used to recursively iterate through:

so

would tell us that nothing was matched and $check would be false otherwise $check would be set to true and our search results would be displayed.

I also wanted to show the page title and a description of the page so using regular expressions once more; I got the title and using PHP’s

would tell us that nothing was matched and $check would be false other wise $check would be set to true and our search results would be displayed.

I also wanted to show the page title and a description of the page so using regular expressions once more; I got the title and using PHP’s

Get a Free Quote

Request a free proposal from Geek Power Web Design and get started on your new website today!

We see every new project as an opportunity to indulge our passion for web design and web development. We truly love what we do and we're always excited to start a new website!

@
Geek Power - Toronto Web Design