At first glance it doesn't seem you can make it much faster, it's just simple sequence of string appending. Unless you have to use it thousands of times and that represents a bottleneck for your application, I'd not waste time make it better, it probably takes a few microseconds, and just upgrading the PHP version would probably make improvements much better than code changes you'd implement.
If you really have to make it faster, possible solutions are - writing it the function into an extension - APC op code caching (it should make things generally fast when interpreting the code so globally increase the speed) - caching results in memory (only if your application runs the same input many times, that is not probably a common case for a simple algorithm like this one)
If you want to play with it and try to make it faster, careful, you could alter the logic and introduce a bug. Always use a unit test, or write some test cases before changing it, always a good practice