Last active
February 20, 2017 04:27
-
-
Save mikestratton/d072940903335eb67e8af5b85098367b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
decipherThis('72olle 103doo 100ya'); // 'Hello good day' | |
echo "<br />"; | |
decipherThis('82yade 115te 103o'); // 'Ready set go' | |
echo "<br />"; | |
decipherThis('a'); // 'a' | |
echo "<br />"; | |
decipherThis('115da'); // 'sad' | |
echo "<br />"; | |
decipherThis('78o'); // 'no' | |
function decipherThis($str){ | |
$decrypted = ''; | |
$ob = ''; | |
if (strlen($str) == 1) | |
{ | |
$decrypted = $str; | |
echo $decrypted; | |
return $decrypted; | |
} | |
$words = explode(" ", $str); // create array of words separated by space | |
$a = count($words); | |
for ($i=0; $i<$a; $i++) | |
{ | |
ob_start(); | |
$words[$i]; | |
$new_str = $words[$i]; | |
$digits_words = preg_split('/(?<=[0-9])(?=[a-z]+)/i',$new_str); | |
$decrypt_ascii = $digits_words[0]; | |
$new_letter = chr($decrypt_ascii); | |
//echo $new_letter; | |
$decrypt_word = $digits_words[1]; | |
if ($digits_words[1] == null) | |
{ | |
echo "<br />null<br />"; | |
$decrypt_word = $digit_words[0]; | |
} | |
$two_letters = $words[$i]; | |
$cnt_letters = strlen($two_letters); | |
if ($cnt_letters == 2) | |
{ | |
$new_word = $digits_words[1]; | |
} | |
$sln = strlen ($decrypt_word); | |
$first = $decrypt_word[0]; | |
$last= $decrypt_word[$sln-1]; | |
$decrypt_word[0] = $last; | |
$decrypt_word[$sln-1] = $first; | |
$new_word = $decrypt_word; | |
if ($i < $a-1) | |
{ | |
$new_word = $decrypt_word . " "; | |
} | |
$output = $new_letter . $new_word; | |
echo $output; | |
$ob .= ob_get_contents(); | |
ob_end_clean(); | |
} | |
ob_start(); | |
print_r($ob); | |
$decrypted = ob_get_clean(); | |
echo $decrypted; | |
return $decrypted; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment