Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active October 21, 2020 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/ac1fa8c93a62deff61aa08fa4b775b3d to your computer and use it in GitHub Desktop.
Save lbvf50mobile/ac1fa8c93a62deff61aa08fa4b775b3d to your computer and use it in GitHub Desktop.
Just PHP FUN 134.
<?php
# https://www.codewars.com/kata/581e014b55f2c52bb00000f8 Decipher this!
function decipherThis($str){
return preg_replace_callback('/\w+/',function($x){
$w = $x[0];
$w1 = digitized_to_str($w);
$w2 = swapper($w1);
return $w2;
},$str);
}
function digitized_to_str($str){
return preg_replace_callback('/[0-9]+/',function($x){ return chr(intval($x[0]));},$str);
}
function swapper($str){
if( 3 > strlen($str)) return $str;
$a = str_split($str);
$l = $a[strlen($str)-1];
$f = $a[1];
$a[1] = $l; $a[strlen($str)-1] = $f;
return implode($a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment