Sha256: 49020fd3f8c506caeae41ccbe44086ae6cb4b4877c836e3b40db3af98eaa64c9

Contents?: true

Size: 593 Bytes

Versions: 396

Compression:

Stored size: 593 Bytes

Contents

<?php

function encode($string)
{
    $a_z = range('a', 'z');
    $z_a = range('z', 'a');
    $string = preg_replace("/[^a-z0-9]+/", "", strtolower($string));
    $len = strlen($string);

    $count = 0;
    $encoded = [];
    foreach (str_split($string) as $char) {
        $count++;
        if (is_numeric($char)) {
            $encoded[] = $char;
        }
        if (ctype_lower($char)) {
            $encoded[] = $z_a[array_search($char, $a_z)];
        }
        if ($count % 5 == 0 && $count < $len) {
            $encoded[] = ' ';
        }
    }

    return implode('', $encoded);
}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.179 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.178 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.177 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.176 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.175 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.174 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.173 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.172 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.171 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.170 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.169 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.167 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.166 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.165 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.164 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.163 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.162 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.161 tracks/php/exercises/atbash-cipher/example.php
trackler-2.2.1.160 tracks/php/exercises/atbash-cipher/example.php