PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Sean Coates' Blog: Arbitrary Incrementer in PHP

Note: This article was originally published at PHPDeveloper on 7 August 2010.
PHPDeveloper

In a new post to his blog Sean Coates shares a technique he's used to pull an arbitrary incrementer from a certain set of characters.

On several recent occasions I had a need for an incrementer that uses an arbitrary character set and I thought I'd share my code with you. I've used this code in the GPL Virus that I wrote to poke fun at the Wordpress/Thesis/GPL debacle, as well as in some clean up I'm doing for the extremely useful JS Bin project.

He's used the technique in an upcoming URL shortening service to make the shortest possible URLs without overlap. He tried a few methods including using dechex and base_convert but they had their limitations. Ultimately, he settled on a custom function that, based on a given character set and increments over it recursively.