<?php // Ůńïčøđē
/**
* @file transliter_russe.php
* @brief Page qui prend en entrée un texte en russe cyrillique et le translite en alphabet latin.
*
* @author hughes monget
* @see http://www.monget.com/
*/
ini_set('default_charset', 'UTF-8');
// (c) YURiQUE (Yuriy Malchenko), 2005
// jmalchenko@gmail.com
//
// A very simple class with more natural cyrillic to latin transliteration.
//
// function Transliterate() takes 3 arguments - the string to transliterate itself,
// an encoding of the input string and an encoding of the result to get.
//
class Translit {
protected $cyr = array(
"Щ", "Ш", "Ч", "Ц","Ю", "Я", "Ж", "А","Б","В","Г","Д","Е","Ё","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х", "Ь","Ы","Ъ","Э","Є","Ї",
"щ", "ш", "ч", "ц","ю", "я", "ж", "а","б","в","г","д","е","ё","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х", "ь","ы","ъ","э","є","ї");
protected $lat = array(
"Shh","Sh","Ch","C","Ju","Ja","Zh","A","B","V","G","D","Je","Jo","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","Kh","'","Y","`","E","Je","Ji",
"shh","sh","ch","c","ju","ja","zh","a","b","v","g","d","je","jo","z","i","j","k","l","m","n","o","p","r","s","t","u","f","kh","'","y","`","e","je","ji"
);
function Transliterate($str, $encIn, $encOut)
{
$str = iconv($encIn, "utf-8", $str);
for($i=0; $i<count($this->cyr); $i++)
{
$c_cyr = $this->cyr[$i];
$c_lat = $this->lat[$i];
$str = str_replace($c_cyr, $c_lat, $str);
}
$str = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]e/", "\${1}e", $str);
$str = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]/", "\${1}'", $str);
$str = preg_replace("/([eyuioaEYUIOA]+)[Kk]h/", "\${1}h", $str);
$str = preg_replace("/^kh/", "h", $str);
$str = preg_replace("/^Kh/", "H", $str);
return iconv("utf-8", $encOut, $str);
}
}
$str_texte = '';
$str_code = '';
if (isset($_REQUEST['texte']) && is_string($_REQUEST['texte']) && strlen($_REQUEST['texte'])
&& isset($_REQUEST['bouton']) && is_string($_REQUEST['bouton']))
{
$str_texte = $_REQUEST['texte'];
if (get_magic_quotes_gpc())
{
$str_texte = stripslashes($str_texte);
}
$obj_translit = new Translit();
$str_code = $obj_translit->Transliterate($str_texte, 'UTF-8', 'UTF-8');
}
function html_encode($s)
{
return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Transliterate</title>
<style type="text/css">
<!--
body *
{
font-family: monospace;
font-size: 8pt;
}
textarea
{
height: 200px;
width: 600px;
}
form
{
margin: 0;
}
div
{
margin: 0 0 5px 0;
}
-->
</style>
<script type="text/javascript">
<!--;
function on_load()
{
if (document && document.getElementById)
{
var obj_input = document.getElementById('texte');
if (obj_input && obj_input.focus)
{
obj_input.focus();
}
}
}
//-->
</script>
</head>
<body onload="on_load();">
<form method="post" action="<?php echo html_encode($_SERVER['SCRIPT_NAME']) ?>">
<div>
<textarea id="texte" name="texte" rows="20" cols="80"><?php echo html_encode($str_texte) ?></textarea>
</div>
<div>
<input type="submit" class="submit" name="bouton" value="Transliterate" />
</div>
</form>
<?php
if ($str_code)
{
echo '<div><textarea rows="20" cols="80" onclick="this.select();">',html_encode($str_code),'</textarea></div>';
}
echo '<hr />';
highlight_file(__FILE__);
?>
</body>
</html>