About Me
26 year old software developer located in Dublin, Ireland.
I work for EngineYard on Orchestra, the PHP Platform as a Service.
Email: ross.duggan@acm.org
-by DuckDuckGo
I run wthax.org and co-founded Ireland's first anime convention, EirtaKon.-
Recent Posts
- Reading list for scaling Solr
- I’m joining EngineYard to work on Orchestra
- Bots are crawling new domain registrations and namesquatting Twitter handles
- “Levelling the playing field” in education
- Munin plugins for Solr
- Google Plus
- Getting Windows 7 onto a USB stick using Ubuntu
- Searching Boards.ie – Solr, EC2, SQS, SNS, Node.js
- EC2: Create AMI from a running instance
- Gender breakdown for software development in Ireland
Recent Comments
- Leon Woodward on Bots are crawling new domain registrations and namesquatting Twitter handles
- SamFisher@SamsungHD on Bots are crawling new domain registrations and namesquatting Twitter handles
- Declan on Bots are crawling new domain registrations and namesquatting Twitter handles
- Sully on I’m joining EngineYard to work on Orchestra
- Ross on I’m joining EngineYard to work on Orchestra
Categories
Development
Recreational
Technology
Base-56 Integer Encoding in PHP
I found myself needing to write a URL-shortening system recently, nothing particularly fancy, just something that would result in URLs similar to those of tinyURL and bit.ly. PHP’s own base64 function is purely for encoding string data to make it “URL safe” and actually results in a longer string. PHP also has a base_convert function, but this only goes up to base-36, and it seemed like a waste to only go as far as base-36 when more can be fit in.
I found a couple of functions written in Python on StackOverflow for base-62 conversion that solved the problem perfectly. The author of the solution, Baishampayan Ghose, also suggested a shorter alphabet (removing similar characters for ease of readability) which would whittle it down to base-56. I’ve ported the functions to PHP and employed a base-56 alphabet in the example below, but it would be trivial to swap it out for a longer one if required.
Usual code-usage caveats apply.