Change code to php from phython
<p>Here i have a coding in python.I've tried to convert this to php.Searched lot of websites and there is no option to define the format with AAAAA-BBBB-CCCC.I just want to use this encrypt and decrypt methods also.Can anyone help me to change this for php or just tell me the logic ??Thanks in advance.</p>

<pre><code>from functools import reduce

def __init__(self, alphabet=None, groups=4):
    if not alphabet:
        alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    self.alphabet = alphabet
    self.groups = groups

def encode(self, txt):
    N = len(self.alphabet)
    num = reduce(lambda x,y: (x*256)+y, map(ord, txt))

    # encode to alphabet
    a = []
    while num &gt; 0:
        i = num % N
        a.append(self.alphabet[i])
        num -= i
        num = num//N

    c = "".join(a)
    if self.groups &gt; 0:
        # right zero pad
        while len(c) % self.groups != 0:
            c = c + self.alphabet[0]
        # make groups
        return '-'.join([c[x*self.groups:(x+1)*self.groups]
                         for x in range(len(c)//self.groups)])
    return c

def decode(self, txt, separator='-'):
    # remove padding zeros and separators
    x = txt.rstrip(self.alphabet[0])
    if separator != None:
        x = x.replace(separator, '')
    N = len(self.alphabet)
    x = [self.alphabet.find(c) for c in x]
    x.reverse()
    num = reduce(lambda x,y: (x*N)+y, x)

    a = []
    while num &gt; 0:
        i = num % 256
        a.append(i)
        num -= i
        num = num//256
    a.reverse()
    return ''.join(map(chr, a))
if __name__ == "__main__":
k = Coder()
s = "Hello world!"
e = k.encode(s)
print("Encoded:", e)
d = k.decode(e)
print("Decoded:", d)
</code></pre>

<p>Example output:</p>

<p>Encoded: D1RD-YU0C-5NVG-5XL8-7620
Decoded: Hello world!</p>
