URL Encoding Performance
This was already pretty optimized, but I moved the trim later and had it match only the 1 space character (since all other spaces degraded to the space). Also, rather than running the preg_replace with the e modifier every time, it drops the modifier when there are no custom replacements.
Just for completeness' sake, I should mention that I looked into accepting UTF-8 characters in URLs, but research showed me that, regardless of the site's language settings, only ASCII characters can be transmitted via URL without turning into % encoded strings. Some browsers may mask this behavior, but I'm pretty sure any proper search engine would index the %.