<?php class Mors{ private static $mors=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"=>"--..","1"=>".----", "2"=>"..---","3"=>"...--","4"=>"....-","5"=>".....","6"=>"-....","7"=>"--...", "8"=>"---..","9"=>"----.","0"=>"-----"," "=>" ","."=>".-.-.-",","=>"--..--", "?"=>"..--..","!"=>"..--.",":"=>"---...","'"=>".----.","\""=>".-..-.", "="=>"-...-","EOM"=>".-.-." ); private static $yazis=array(); static function kelime($kelime){ mb_strtolower($kelime); $kelime = str_replace("&", "&", $kelime); $kelime = preg_replace("/&([a-z]+);/", "", $kelime); $kelime = str_replace( array("$","^","*",";","%","~","@","#","[","]","<",">","\\","/","+"), "", $kelime); $kelime = str_replace( array('_',"&",'ç','ş','ı','í','ì','î','ï','ú','ü','ù','û','á','ä','â','à','â','ó','ö','ò','ô','ô','ğ'), array("-","ve",'c','s','i','i','y','y','i','u','u','u','u','a','a','a','a','a','o','o','o','o','o','g'), $kelime); return strtolower($kelime); } static function MorsaCevir($kelime) { $kelime=Mors::kelime($kelime); $yazdir = ""; for ($i = 0; $i < strlen($kelime); $i++) { $yazi = substr($kelime,$i,1); // ignore unknown harfacters if (self::$mors[$yazi] == "") continue; $yazdir .= (self::$mors[$yazi]." "); } return trim($yazdir); } static function YaziyaCevir($kelime) { $kelime = strtolower($kelime); reset(self::$mors); while (list($yazi,$kod) = each(self::$mors)) { self::$yazis[$kod] = $yazi; } $yazdir = ""; $kelimeler = array(); $harfler = array(); $kelimeler = preg_split("/".self::$mors[" "]."/", $kelime, -1, PREG_SPLIT_NO_EMPTY); foreach ($kelimeler as $kelime) { $harfler = array_merge($harfler, preg_split("/ /", $kelime, -1, PREG_SPLIT_NO_EMPTY)); $harfler[] = ''; } $harfler[count($harfler)-1] = self::$mors["EOM"]; foreach ($harfler as $harf) { // ignore unknown harfacters if ($harf == "") { $yazdir .= " "; } if ($harf == self::$mors["EOM"]) { break; } if (@self::$yazis[$harf] == "") { continue; } $yazdir .= self::$yazis[$harf]; } return trim($yazdir); } } echo $mors=Mors::MorsaCevir('Bu bir deneme yazısıdır'); echo '<br>'; echo Mors::YaziyaCevir($mors); ?>
Çıktısı
-... ..- -... .. .-. -.. . -. . -- . -.-- .- --.. .. ... .. -.. .. .-. bu bir deneme yazisidir