Advertisement
D3vBl4ck

Morse Decode with PHP

Jun 27th, 2020
15,621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2. function decode(string $code): string {
  3.     $decode = "";
  4.     foreach (explode(" ", str_replace("   ", " ._. ", $code)) as $ms) {
  5.         $decode .= array_search($ms, [" " => "._.",";"=>"-.-.-.","="=>"-...-","O"=>"---","9"=>"----.","/"=>"-..-.","&"=>".-...","3"=>"...--","W"=>".--","M"=>"--","Z"=>"--..","'"=>".----.","!"=>"-.-.--","B"=>"-...","U"=>"..-","1"=>".----",")"=>"-.--.-","A"=>".-","-"=>"-....-","V"=>"...-","SOS"=>"...---...","Y"=>"-.--","I"=>"..","Q"=>"--.-","N"=>"-.","2"=>"..---","6"=>"-....",","=>"---...","+"=>".-.-.","@"=>".--.-.","4"=>"....-","0"=>"-----","."=>".-.-.-","C"=>"-.-.","E"=>".","F"=>"..-.","J"=>".---","K"=>"-.-","L"=>".-..","R"=>".-.","S"=>"...","G"=>"--.","8"=>"---..","?"=>"..--..","("=>"-.--.","P"=>".--.","5"=>".....","_"=>"..--.-","D"=>"-..","\\"=>".-..-.","T"=>"-","H"=>"....",","=>"--..--","$"=>"...-..-","7"=>"--...","X"=>"-..-"]);
  6.     }
  7.     return $decode;
  8. }
  9. //".... . -.--   .--- ..- -.. ." = HEY JUDE
  10. echo decode(".... . -.--   .--- ..- -.. .");
  11. //codewars.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement