Creating SEO Friendly URLs in PHP with url_slug()

I’m talking about slugs, SEO friendly URLs, clean URLs, permalinks, etc. You know, those nice-looking URLs that are easy to read (for humans and search engines). The keywords that show up in your URLs plan an important role in how well your site ranks in search results. That’s one reason why it’s common for blogging systems like WordPress to create permalinks from post titles. I’ve had a function in my toolbox for doing this sort of thing for a while now. While working on an article management system the other day, though, I decided to take another look at it […]

mb_str_replace — The Missing PHP Function

I usually try to build UTF-8 support into the sites and web applications I build. In PHP land that usually means using the multibyte string extension mbstring. A number of people have noticed, though, that there are some often used PHP string functions with no mbstring equivalent. One of those functions is str_replace(). So for anyone looking for a mb_str_replace() function the one below should serve you nicely. It should work in exactly the same manner as str_replace().

Binary Search for Javascript Arrays

If you need to search through a large array, or you search arrays frequently in your Javascript code, or if you do both, chances are a binary search will give you better performance than a linear search (read: for loop). One caveat, however, is that binary search algorithms only work on sorted arrays. Here is a binary search function I sometimes use in my code:

Auto-Linking URLs with PHP

A week or so ago I was working on a bug in the auto-linking code for Laconica, the software that powers Squashing that particular bug wasn’t too hard, but I wanted to take the functionality a step further (closer to the calibre of Gmail) and it turns out, writing robust auto-linking code is more difficult than it initially seems. So I played with it a little at a time here and there, testing as many edge cases as I could think of. The result is a function that’s more robust than most URL auto-linking code I’ve come across. I […]

LongURL—Restoring Order to the Universe

It’s been two weeks since I conceptualized LongURL, and a productive two weeks at that! Last Monday I officially launched the service (which provides a handy REST API) with support for a dozen or so shortening services like Once I stepped away from the problem for a little while I realized there was a better way to go about solving it. Thankfully the way I designed the service didn’t make it very difficult to swap out that bit of business logic, so this week I rolled-out an update that adds support for all shortening services. After getting feedback from […]