Search code examples
phpurlencodebase36

How Do I Encode a Unicode String in Base36 in PHP?


I have learned how to Base16 encode a string in PHP, but how do I Base36 encode and decode a string in PHP?

Note I need this to make the string work in URLs.

BONUS: And if you know how to compress the string slightly first before doing the Base36, that would be even cooler! :)


Solution

  • Google told me this: http://darklaunch.com/2009/07/31/base36-encode-and-decode-using-php-with-example-base36-encode-base36-decode

    Anyway, base64 should fit your needs if you want to use it inside an URL.

    Bonus: gzcompress() and gzuncompress() ;) (Zlib extension must be installed).