I did this in ASP a few years ago. It was rather simple. Although I don't have the code. Where are you getting stuck at? Have you tried coding the algorithm from scratch? If I remember correctly, it was only about 5 or 7 lines of ASP JScript code which would probably be about the same in PHP. Although its been a while and I might be thinking of some other code...
I'll see if I can find the algorithm and see if I can build it from scratch.