Last active
December 29, 2018 01:05
-
-
Save nhalstead/678f8b2ad09d3722309cf2d0186ef17b to your computer and use it in GitHub Desktop.
Take a regular string and convert it into a NATO Alphabet Message
This file contains hidden or 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 | |
const NATOAlphabet = array( | |
"A" => "Alfa", | |
"B" => "Bravo", | |
"C" => "Charlie", | |
"D" => "Delta", | |
"E" => "Echo", | |
"F" => "Foxtrot", | |
"G" => "Golf", | |
"H" => "Hotel", | |
"I" => "India", | |
"J" => "Juliett", | |
"K" => "Kilo", | |
"L" => "Lima", | |
"M" => "Mike", | |
"N" => "November", | |
"O" => "Oscar", | |
"P" => "Papa", | |
"Q" => "Quebec", | |
"R" => "Romeo", | |
"S" => "Sierra", | |
"T" => "Tango", | |
"U" => "Uniform", | |
"V" => "Victor", | |
"W" => "Whiskey", | |
"X" => "X-ray", | |
"Y" => "Yankee", | |
"Z" => "Zulu", | |
"0" => "Zero", | |
"1" => "One", | |
"2" => "Two", | |
"3" => "Three", | |
"4" => "Four", | |
"5" => "Five", | |
"6" => "Six", | |
"7" => "Seven", | |
"8" => "Eight", | |
"9" => "Nine", | |
); | |
$string = "Hello this is a Test 058157"; | |
$string = preg_replace('/\s+/', '', $string); // Removes all spaces | |
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. | |
$string = str_split($string); | |
$out = ""; | |
foreach($string as $c){ | |
if(!isset(NATOAlphabet[ strtoupper($c) ])){ | |
continue; | |
} | |
$out .= " ".NATOAlphabet[ strtoupper($c) ]; | |
} | |
// Example Output: Hotel Echo Lima Lima Oscar Tango Hotel India Sierra India Sierra Alfa Tango Echo Sierra Tango Zero Five Eight One Five Seven | |
echo $out; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment