PHP port of Dan Palmer's jquery.complexify.js