Simple text search in PHP

To search my music-collection via my browser, I’m currently browsing and searching my webbased interface with the browser itself.
I head my Firefox to http://fileserver/music/, and I get the FancyIndexed list of music on the M-partition. As this list is growing to be quite large nowadays, I can still search for albums by ctrl-f’ing to my desired destination; yet this doesn’t work for individual tracks.

I’ve been building a text-based index of all tracks and albums on the disk, via a daily scheduled bat-file which exports its result to a plain text file.
To search this text file, I’ve created a small search-script in PHP, which can search all entries for a certain string. All is well up until this point.

Now here’s the catch: I want to implement a boolean search with the basic operands such as AND, OR and NOT available to be used in the search-query.
This would be my ideal form of searching with multiple arguments. I’ve got this implemented at this moment, it however searches for the concatenation of the entire string, instead of the existence of all or at least one of the substrings in an entry.

For instance: I want my algorithm to find “(09) – Technohead – I Wanna Be A Hippy.mp3” when I search for “technohead hippy”. The algorithm should match both “technohead” and “hippy”, regardless of their location in the string. At this moment, the search for the same arguments wouldn’t yield this track as a result as the exact string “technohead hippy” does not occur in the entry. Searching on “technohead” or “hippy” would point to this track, however it is not ideal as many other tracks will also match the widened search.

Now going back to why I’m posting this: Is there anyone who can point me to a proper, text based, solution?
I know it can quite easily be solved with a fulltext search in a database, but I would like to stay away from the DB as long as possible.
Also, re-searching all hits on the first argument (when AND is given in the search) with all other arguments is a possibility. The issue is that the other operands like OR and NOT are a little harder to implement.
I feel a nudge in the right direction would help me a lot, so I’m appealing to the better nature of all readers here. 😉

I started implementing an auto-AND functionailty; while still working from my plain-text file.
I created the following code.

// insert some form-stuff

$haystack = file(”filelist.txt”);
$needles = array_reverse(explode(” “, chop($formData['needle'])));
$i = sizeof($haystack);
foreach($needles as $needle) {
$haystack = searchStack($needle, $haystack);
$j = sizeof($haystack);
if($j == 0) {
$sOut .= “Helaas is er niets gevonden.

} else {
$sOut .= formatFound($haystack);
$sOut .= ‘
Found: ‘.$j.’ items.
Searched ‘.$i.’ files and folders.’;

function searchStack($needle, $haystack) {
$tempstack = array();
foreach($haystack as $straw) {
if(stristr($straw, $needle) !== false) {
array_push($tempstack, $straw);
return $tempstack;

function formatFound($haystack) {
$sOut = “”;
foreach($haystack as $straw) {
// do some magical tricks in modifying the filename & location to a URL
return $sOut;

Any comments are always welcome.

New header images

As many of you would have noticed, almost directly after changing my layout, I also changed the default image at the top.

I made a list of header-images, for you all to gleam upon without you having to f5 20-ish times before all headers would have taken their turn at the top.
So: enjoy!

I will be adding some more soon, if I shoot some photos worth adding 🙂

Technical information: All but 2 or 3 were made with my Nikon D40 and either the Nikkor AF-S 18-55 ED DX II, or the Nikkor AF-S 55-200 ED DX, the others were taken with my trusty Canon Ixus 30. Generally speaking; the pictures with bokeh come from the Nikon dSLR 😉

Sad news

This morning, my former boss in Hoogvliet tried to call me but could’t reach me, so he left an urgent message for me to call him back.
As he refused to say to my parents what it was about, they feared the worst: something really bad had happened to someone I knew.

I got back a short while later to find out I had a message, and so I rang my former boss only to hear what I had been fearing I would hear: something really bad had happened.

Cutting this story short: my former colleague and not-too-distant friend Joep has passed away at the age of 24.
Only just engaged to his girlfriend Paula, they had bought a house and he was planning on some good things to happen.
We can only say Joep’s passing was quick and completely unforeseen.

From here, and in this quite impersonal distant digital fashion I would like to condole his family, fiancé and his friends with the terrible loss.

In the remembrance of Joep Wesseling (1982-2007)

A warm welcome

As many of you know, I’m currently doing an internship at Ordina since the last week of July. To my great surprise, I found a note yesterday stating I could collect a bouquet delivered for a mr. Tijhof. Curious as I was, I went to our neighbours to retrieve the flowers only to find out they were sent for me! Who on earth could be sending ME a flower bouquet? Turns out it’s from the business unit I’m currently doing my internship with, so I’d like to thank you all for this fine present!


Back in town

Right, after a very refreshing two-week stay at some tiny town in Austria, I’ve learned quite a few things about the place, and the very first would be: Internet is not something the Austrians would consider a necessity.

During my twitching and eye-twisting my girlfriend tried to distract my attention from the lack of internet-access to more relaxing things like walking the awfully beautiful mountain-trails available at Ötztal or the fine local cuisine, the latter led to some very fine pizza-eating which, given the fact we were only about 40km away from the Italian border is not astonishing.

I very possibly will post some pics when I’m back home I placed some pictures below (see the update), we’ve taken scandalous amounts of photos in those 14 short days.

Anyway, it’s good to be back, and it’s good to have been on holiday. I’ve rested enough to turn my attention fully to the three most important things in the upcoming months: my masterthesis, my sport and my friends and relatives.

 UPDATE: please click "Read More" to see a small selection of my photo’s.

Continue reading “Back in town”


This time of year, it seems a lot of people are taking a few days off to go some place the sun always shines.
Turkey, Italy, Spain, Portugal and Egypt are popular destinations, as is France for most Dutchies.

Next week, I’m also AWOL, I’m going to Austria with my girlfriend to breathe in some healthy and fresh mountain air, and get some excercise by walking the mountain trails.
Because of my holidays, I will most likely not post anything for the upcoming couple of weeks, unless our accommodation not only features a stunning view but also (wireless) internet.
I’m definately not counting on it, so you’ll have to bear with me here as I’m already starting to show withdrawal symptoms by simply thinking about it.

Oh well, I’ll just drink another coffee and start pondering how to get through the day 🙂


Although the astronomical summer already a few weeks there is, we haven’t noticed anything. Our weather could very well be the same as during the Spring, or even Autumn. Yesterday, I’ve been witnessing quite some downpoor here at nieuwegein, and we will not even start about last Monday…

The one thing that reminds us of the fact it should be nice out there is the life outside, and last Friday I found quite a nice example of that.


If anyone knows what species this is, please post a comment.

Update: Some research showed me that it is in fact the most common butterfly in Europe!
We Dutchies know it as an “Atalanta“, in English speaking countries they know it as a “Red Admiral“.
The latin name is “Vanessa atalanta“, which makes absolutely no sense to me at all.
Below a nice picture which is not made by me.


Temporarily busy

Yes, my life being a student does have it’s rough edges from time to time.
After getting graded an 8 for our seminar-document (which is kind of depressing considering the good comments we received during the seminar, and the bulky document we’ve come up with. I know, quantity is not quality, but we’ve tried to be as complete as we could. I’ve got a slight suspicion we’ve been "undergraded" as we’ve not only doubted the course itself, we’ve also come up with a solution which doesn’t fit our professor’s views fully.
However, I’m not moaning over it as it would be childish to moan at an 8; but it would have been nice to get a higher grade in comparison to the other groups.)

Anyway, that was not why I’m about to post this: it’s because of my probable inactivity the next couple of days (weeks maybe?) as I’m currently very busy reading and studying for the upcoming exams. Yes, both of them.

Maybe I’ll post some stuff that’s catching my interest sooner or later, so far I’m not sure when that’ll be.
Thanks for reading this now. To shamelessly quote some Austrian guy:

I’ll be back!