function morse ($data, $direction
{
$codes = array
'a' => '.-'
'b' => '-...'
'c' => '-.-.'
'd' => '-...'
'e' => '.'
'f' => '..-.'
'g' => '--.'
'h' => '....'
'i' => '..'
'j' => '.---'
'k' => '-.-'
'l' => '.-..'
'm' => '--'
'n' => '-.'
'o' => '---'
'p' => '.--.'
'q' => '--.-'
'r' => '.-.'
's' => '...'
't' => '-'
'u' => '..-'
'v' => '...-'
'w' => '.--'
'x' => '-..-'
'y' => '-.--'
'z' => '--..'
'0' => '-----'
'1' => '.----'
'2' => '..---'
'3' => '...--'
'4' => '....-'
'5' => '.....'
'6' => '-....'
'7' => '--...'
'8' => '---..'
'9' => '----.'
',' => '--..--'
'.' => '.-.-.-'
'?' => '..--..'
);
$output = ''
if ($direction=='text') {
$codes = array_flip$codes);
$elements = explode' ', $data);
foreach ($elements as $element) {
if (array_key_exists$element, $codes))
$output .= $codes$element];
}
} else {
$data = strtolower$data);
$elements = str_split$data);
foreach ($elements as $element) {
if (array_key_exists$element, $codes))
$output .= $codes$element].' '
}
$output = trim$output);
}
return $output
}