PHP base64 encoding custom alphabet

php

Solution

Ultra easy, `strtr` can do this out of the box:

$default = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
$custom  = "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210+/";

$encoded = strtr(base64_encode($input), $default, $custom);

Problem

I try to use base64_encode() and base64_decode() but with custom alphabet. Default alphabet is: ``` "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ``` say I want to use: ``` "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210+/" ``` found a class on internet but doesn't work as expected. Any idea on how to achieve this as simple as possible?

Original source

Related problems