View file guest/index.php

File size: 20.8Kb
<?
ob_start("rus");
$admin = "[email protected]";
$autor= array("Wap",$admin,"admin");
$nums = 3;   // количество сообшений на странице
$adminka="No";
if (!empty($nm)) if ($nm==$autor[0])
if (!empty($ml)) if ($ml==$autor[1])
if (!empty($tx)) if ($tx==$autor[2])
{$adminka="Yes"; $nums = 1;}
if (($adminka=="Yes")&&(isset($ad))&&(isset($num))){
$ad= substr(zashita(trim($ad)),0, 500);
$fp = file("index.dat");
$total= count($fp);
$tuda= (int)$fp[$total-$num-1];
$fp[$total-$num-1]= substr("0000000".filesize("gostev.dat"), -7).chr(13).chr(10);
$mas=false;
foreach($fp as $a) $mas[]=trim($a);
saveserg("index.dat",$mas);    // тут происходит изменение файла индексов так как админ дал ответ
$fp = fopen ("index.dat", "a+"); // это новый обнаруженный глюк после добавления сообщений
fputs($fp, chr(13).chr(10));
fclose($fp);
$fp= fopen("gostev.dat", "r");
fseek ($fp,$tuda, SEEK_SET);
$p = fgets($fp);
fclose($fp);
list($data,$name,$mail,$text,$answer)=explode("#|#",$p);
$fp = fopen("gostev.dat", "a+");
fputs($fp, "$data#|#$name#|#$mail#|#$text#|#$ad#|#".chr(13).chr(10));
fclose($fp);
}
if ($adminka=="No"){
if (empty($ml)) $ml=" ";
if (!empty($tx)) $go="add";
if (!empty($nm)) {
$go="add";
if (!empty($tx)) $go="rec";
}}
if ($adminka=="Yes") if (!empty($go)) if ($go=="del") if(isset($num)) {
$filename="index.dat";
if (!file_exists($filename))
{
$fp = fopen($filename, "w");
fclose($fp);
}
$fp = file($filename);
$total=count($fp);
$fp[($total-$num-1)]=false;
$mas=false;
foreach($fp as $a)if ($a<>false) $mas[]=trim($a);
if ($mas==false){
$fp = fopen($filename, "w");
fclose($fp);
}else {
saveserg($filename,$mas);
$fp = fopen ("index.dat", "a+"); // это новый обнаруженный глюк после удаления сообщений
fputs($fp, chr(13).chr(10));
fclose($fp);
}

$go=" ";
}
if (empty($go)) $go=" ";
$er1=0;
$er2=0;
if ($go=="rec"){
$tx= zashita($tx);
$nm= zashita($nm);
$tx=substr(trim($tx),0, 500);
$nm=substr(trim($nm),0, 10);
$ml=substr(trim($ml),0, 32);
if ((count(explode(" ",$ml)))>1) {$go="add"; $er1=1;}
if  (!(validEmail($ml))) {$go="add"; $er2=1;}
if ($go!="add"){
// проверка на наличие такого сообщения
$ret= 1;
$filename="linego.dat";
if (!file_exists($filename))
{
$fp = fopen($filename, "w");
fclose($fp);
}
$fp = file($filename);
$a= $nm.$ml.$tx;
$massiv[]=$a."#||#".time();
foreach ($fp as $p) {
$znach= explode("#||#",$p);
if (($znach[1]+600) > time()) $massiv[]=rtrim($p);
if ($znach[0]==$a) $ret= 0;
}
saveserg($filename,$massiv);
if ($ret==1) {
// проверка  окончена
$fp = fopen ("index.dat", "a+");
fputs($fp, substr("0000000".filesize("gostev.dat"), -7).chr(13).chr(10));
fclose($fp);
$fp = fopen("gostev.dat", "a+");
fputs($fp, strftime("%d.%m.%y %H:%M#|#")."$nm#|#$ml#|#$tx#|##|#".chr(13).chr(10));
fclose($fp);
}else  $go=" ";
}
}
if ($go!="add"){
$num2 = $nums;
$filename="gostev.dat";
if (!file_exists($filename))
{
$fp = fopen($filename, "w");
fclose($fp);
}
$filename="index.dat";
if (!file_exists($filename))
{
$fp = fopen($filename, "w");
fclose($fp);
}
$fp = file($filename);
$total=count($fp);
if (empty($total)) $s="Гостевая книга пуста.";
              else $s="Всего сообщений: $total";

header("Content-Type: text/vnd.wap.wml; charset=UTF-8");
print '<?xml version="1.0"?>';
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="index" title="Гостевая"<? if ($go=="rec") print ' newcontext="true"' ?>>
<p align="center">
<table columns="1">
<tr>
<td>
<b>
<?print $admin;?>
</b>
</td>
</tr>
<tr>
<td>
<?print $s;?>
</td>
</tr>
</table>
<?if ($go=="rec") print "Сообшение успешно добавлено.<br/>";
?>
</p>
<?
if (!empty($total)) {
if(empty($num)) $num=0;
if ($num>($total-1)) $num=$total-1;
$num=abs($num);
$fp = array_reverse($fp);
$s=false;
for($i=$num; $i<min($num+$nums,$total); $i++) $s[]=(int)$fp[$i];
$fp= fopen("gostev.dat", "r");
$p=false;
foreach($s as $i){
fseek ($fp,$i, SEEK_SET);
$p[] = fgets($fp);
}
fclose($fp);
$er1=0;
foreach ($p as $i){
list($data,$name,$mail,$text,$answer)=explode("#|#",$i);
?>
<p>
<table columns="1">
<tr>
<td>
<?=htmlspecialchars($data)."&nbsp;&nbsp;-".($total-$num-$er1)."-"?>
</td>
</tr>
<tr>
<td>
<b>
Name:
</b>
<?=(dollar(htmlspecialchars($name)))?>
<br/>
<?
$er1++;
if (!empty($mail)){
?>
<b>
E-mail:
</b>
<?
if ($adminka<>"Yes"){
print htmlspecialchars($mail);
}else{
?>
<a href="../mail.php?<? print rand(0,100000)."&amp;m_t=".htmlspecialchars($mail)."&amp;m_r=gostev/?go=add%26num=$num";?>">
<?print htmlspecialchars($mail);?>
</a>
<?}
?>
<br/>
<?
}
?>
<b>
Text:
</b>
<?=(http($text));
if (!empty($answer)){
?>
<br/>
<b>
Admin:
</b>
<?=(http($answer))?>
<?
}
?>
</td>
</tr>
</table>
<?
if (($adminka=="Yes")&&($go=="ans")){
?>
<input name="data" title="Ответ Админа" emptyok="true" type="text" value="" maxlength="500"/>
</p><p>
<anchor>
Send
<go method="post" href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;num=$num"?>">
<postfield name="nm" value="<?=htmlspecialchars($nm)?>"/>
<postfield name="ml" value="<?=htmlspecialchars($ml)?>"/>
<postfield name="tx" value="<?=htmlspecialchars($tx)?>"/>
<postfield name="ad" value="$(data)"/>
</go>
</anchor>
<?
}else{
if ($adminka=="Yes"){
?>
<anchor>
Delete
<go method="post" href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;go=del&amp;num=$num"?>">
<postfield name="nm" value="<?=htmlspecialchars($nm)?>"/>
<postfield name="ml" value="<?=htmlspecialchars($ml)?>"/>
<postfield name="tx" value="<?=htmlspecialchars($tx)?>"/>
</go>
</anchor>
&nbsp;&nbsp;&nbsp;
<anchor>
Answer
<go method="post" href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;go=ans&amp;num=$num"?>">
<postfield name="nm" value="<?=htmlspecialchars($nm)?>"/>
<postfield name="ml" value="<?=htmlspecialchars($ml)?>"/>
<postfield name="tx" value="<?=htmlspecialchars($tx)?>"/>
</go>
</anchor>
&nbsp;&nbsp;&nbsp;
<anchor>
Next
<go method="post" href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;go=nex&amp;num=".($num+1)?>">
<postfield name="nm" value="<?=htmlspecialchars($nm)?>"/>
<postfield name="ml" value="<?=htmlspecialchars($ml)?>"/>
<postfield name="tx" value="<?=htmlspecialchars($tx)?>"/>
</go>
</anchor>
&nbsp;&nbsp;&nbsp;
<a href="<? print $PHP_SELF."?p=".rand(0,100000)?>">
Exit
</a>
<?
}}
print '</p>';
}
//навигация
$page_next = $num + $nums;
$page_prev = $num - $nums;
$page_next1 = $num + ($nums + $num2);
$page_prev1 = $num - ($nums + $num2);
$num3 = $total - $num2;
$p=ceil($page_next/$nums);
$d=abs($p+1);
$dd=abs($d+1);
$n=abs($p-1);
$nn=abs($n-1);
if ($adminka=="No"){
?>
<p>
стр.
<?
if ($num > $num2){
?>
<a href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;num=$page_prev1".'">'.$nn;?>
</a>
<?
}
if ($num >=$nums){
?>
<a href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;num=$page_prev".'">'.$n;?>
</a>
&#8592;
<?
}
echo "<b>$p</b>";
if (($num + $nums) < $total){
?>
&#8594;
<a href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;num=$page_next".'">'.$d;?>
</a>
<?
}
if (($num + $num2) < $num3){
?>
<a href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;num=$page_next1".'">'.$dd;?>
</a>
<?
}
?>
</p>
<?
}}
?>
<p align="center">
***
</p>
<?if ($adminka<>"Yes"){ ?>
<p align="center">
<a href="<? print $PHP_SELF."?p=".rand(0,100000)."&amp;go=add"; if (!empty($num)) print "&amp;num=$num";?>">
Добавить сообщение
</a>
</p>
<?}?>
<p>
<a href="../<? print "?p=".rand(0,100000); ?>">
На главную &#169; <?print getenv('SERVER_NAME');?>
</a>
</p>
</card>
</wml>
<?
}else{
header("Content-Type: text/vnd.wap.wml; charset=UTF-8");
print '<?xml version="1.0"?>';
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="index" title="Новое сообщение">
<p align="center">
<table columns="1">
<tr>
<td>
<b>
<?print $admin;?>
</b>
</td>
</tr>
<tr>
<td>
<?print strftime("%d.%m.%y %H:%M")?>
</td>
</tr>
</table>
</p>
<p align="center">
Name:
<br/>
<?
if (!empty($tx)) if (empty($nm)) print "Введите этот обязательный параметр<br/>";
?>
<input name="name" emptyok="true" title="Обязательно" type="text" <? if (!empty($nm)) print 'value="'.(zashita(htmlspecialchars($nm))).'"'?> maxlength="10"/>
</p>
<p align="center">
Mail:
<br/>
<?
if ($er1==1) print "Пробелы не нужны<br/>";
if ($er2==1) print "Адрес должен быть [email protected]<br/>";
?>
<input name="mail" emptyok="true" title="По желанию" type="text" value="" maxlength="32"/>
</p>
<p align="center">
Text:
<br/>
<a href="smview.php<?="?p=".rand(0,100000)?>">
Список смайлов
</a>
<br/>
<?
if (!empty($nm)) if (empty($tx)) print "Введите этот обязательный параметр<br/>";
?>
<input name="text" emptyok="true" title="Обязательно" type="text" <? if (!empty($tx)) print 'value="'.(zashita(htmlspecialchars($tx))).'"'?> maxlength="500"/>
</p>
<p align="center">
<anchor>
Добавить
<go method="post" href="<? print $PHP_SELF."?p=".rand(0,100000); if (!empty($num)) print "&amp;num=$num"; ?>">
<postfield name="nm" value="$(name)"/>
<postfield name="ml" value="$(mail)"/>
<postfield name="tx" value="$(text)"/>
</go>
</anchor>
</p>
</card>
</wml>
<?
}
// конец кода WML ***********************************
ob_end_flush();

function validEmail($email) {
if (eregi("^[a-z0-9_]+([-_\.]?[a-z0-9_])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email))
    return TRUE;
else
    if (strlen($email)===0) return TRUE;
    else return FALSE;
}

function saveserg($filename,$mas){
$a="";
foreach ($mas as $zn) $a.=$zn.chr(13).chr(10);
$fp = fopen($filename, "w");
fputs($fp, trim($a));
fclose($fp);
}
function http($a){
$mark="#+|+#";
$str=array($mark => "");
$a=strtr($a, $str); // вырезали на всякий случай
$a=" $a ";
$s="";
$razd=array("http://", "www.", "wap.");
$str=array(
" $razd[0]" => " $mark$razd[0]",
" $razd[1]" => " $mark$razd[1]",
" $razd[2]" => " $mark$razd[2]",
);
$a=strtr($a, $str);
//print  "-$a-<br/>".(count(explode(" $mark", " $a"))-1);
$f=(count(explode(" $mark", " $a"))-1);
for ($i=1; $i<=$f;$i++)  {
//print "-$i-<br/>";
// найдена ссылка
$t= strpos($a," $mark");
if (!empty($t)) $s.= smile(htmlspecialchars(substr($a,0,$t)));
$ssyl= substr($a,$t-strlen($a)+ strlen(" $mark"));
$a=strstr($ssyl," ");
if (!empty($a)) $s.= vydel(substr($ssyl,0,-strlen($a)));
}
print (zashita($s.smile(htmlspecialchars($a))));
}

function vydel($a){
$s=array("&");  // вдруг есть еще какие символы
$l=true;
foreach($s as $q){
$w=strtr($a,$q," ");
if (htmlspecialchars($w)!=$w) $l=false;
}
if ($l){
$fp= array_reverse(explode(" http://",strtolower(" $a")));
$s= htmlspecialchars(trim($fp[0]));
$a= '<a href="http://'.$s.'">'.htmlspecialchars($a).'</a>';
return "&nbsp;$a&nbsp;";
}else return smile(htmlspecialchars($a));
}

function dollar($a){
$str=array("$" => "$$");
return strtr($a, $str);
}

function smile($s){
$s=str_replace(" .ulibka. ","&nbsp;<img src=\"smiles/biggrin.gif\" alt=\".ulibka.\"/>&nbsp;",$s);
$s=str_replace(" .blush. ","&nbsp;<img src=\"smiles/blush.gif\" alt=\".blush.\"/>&nbsp;",$s);
$s=str_replace(" .boggle. ","&nbsp;<img src=\"smiles/boggle.gif\" alt=\".boggle.\"/>&nbsp;",$s);
$s=str_replace(" .confused. ","&nbsp;<img src=\"smiles/confused.gif\" alt=\".confused.\"/>&nbsp;",$s);
$s=str_replace(" .cool. ","&nbsp;<img src=\"smiles/cool.gif\" alt=\".cool.\"/>&nbsp;",$s);
$s=str_replace(" .eek. ","&nbsp;<img src=\"smiles/eek.gif\" alt=\".eek.\"/>&nbsp;",$s);
$s=str_replace(" .huh. ","&nbsp;<img src=\"smiles/huh.gif\" alt=\".huh.\"/>&nbsp;",$s);
$s=str_replace(" .inlove. ","&nbsp;<img src=\"smiles/inlove.gif\" alt=\".inlove.\"/>&nbsp;",$s);
$s=str_replace(" .mad. ","&nbsp;<img src=\"smiles/mad.gif\" alt=\".mad.\"/>&nbsp;",$s);
$s=str_replace(" .notsure. ","&nbsp;<img src=\"smiles/notsure.gif\" alt=\".notsure.\"/>&nbsp;",$s);
$s=str_replace(" .ooh. ","&nbsp;<img src=\"smiles/ooh.gif\" alt=\".ooh.\"/>&nbsp;",$s);
$s=str_replace(" .rolleyes. ","&nbsp;<img src=\"smiles/rolleyes.gif\" alt=\".rolleyes.\"/>&nbsp;",$s);
$s=str_replace(" .sad. ","&nbsp;<img src=\"smiles/sad.gif\" alt=\".sad.\"/>&nbsp;",$s);
$s=str_replace(" .sleep. ","&nbsp;<img src=\"smiles/sleep.gif\" alt=\".sleep.\"/>&nbsp;",$s);
$s=str_replace(" .smile. ","&nbsp;<img src=\"smiles/smile.gif\" alt=\".smile.\"/>&nbsp;",$s);
$s=str_replace(" .stress. ","&nbsp;<img src=\"smiles/stress.gif\" alt=\".stress.\"/>&nbsp;",$s);
$s=str_replace(" .tired. ","&nbsp;<img src=\"smiles/tired.gif\" alt=\".tired.\"/>&nbsp;",$s);
$s=str_replace(" .tongue. ","&nbsp;<img src=\"smiles/tongue.gif\" alt=\".tongue.\"/>&nbsp;",$s);
$s=str_replace(" .urgh. ","&nbsp;<img src=\"smiles/urgh.gif\" alt=\".urgh.\"/>&nbsp;",$s);
$s=str_replace(" .wink. ","&nbsp;<img src=\"smiles/wink.gif\" alt=\".wink.\"/>&nbsp;",$s);
$s=str_replace(" .worry. ","&nbsp;<img src=\"smiles/worry.gif\" alt=\".worry.\"/>&nbsp;",$s);
$s=str_replace(" .vopros. ","&nbsp;<img src=\"smiles/vopros.gif\" alt=\".vopros.\"/>&nbsp;",$s);
$s=str_replace(" .pivo. ","&nbsp;<img src=\"smiles/pivo.gif\" alt=\".pivo.\"/>&nbsp;",$s);
$s=str_replace(" .be. ","&nbsp;<img src=\"smiles/be.gif\" alt=\".be.\"/>&nbsp;",$s);
$s=str_replace(" .bumbum. ","&nbsp;<img src=\"smiles/bumbum.gif\" alt=\".bumbum.\"/>&nbsp;",$s);
$s=str_replace(" .eat. ","&nbsp;<img src=\"smiles/eat.gif\" alt=\".eat.\"/>&nbsp;",$s);
$s=str_replace(" .sleza. ","&nbsp;<img src=\"smiles/sleza.gif\" alt=\".sleza.\"/>&nbsp;",$s);
$s=str_replace(" .chmok. ","&nbsp;<img src=\"smiles/chmok.gif\" alt=\".chmok.\"/>&nbsp;",$s);
$s=str_replace(" .ne.znayu. ","&nbsp;<img src=\"smiles/ne.znayu.gif\" alt=\".ne.znayu.\"/>&nbsp;",$s);
$s=str_replace(" .jump. ","&nbsp;<img src=\"smiles/jump.gif\" alt=\".jump.\"/>&nbsp;",$s);
$s=str_replace(" .good. ","&nbsp;<img src=\"smiles/good.gif\" alt=\".good.\"/>&nbsp;",$s);
$s=str_replace(" .chmak. ","&nbsp;<img src=\"smiles/chmak.gif\" alt=\".chmak.\"/>&nbsp;",$s);
$s=str_replace(" .clock. ","&nbsp;<img src=\"smiles/clock.gif\" alt=\".clock.\"/>&nbsp;",$s);
$s=str_replace(" .zubastik. ","&nbsp;<img src=\"smiles/zubastik.gif\" alt=\".zubastik.\"/>&nbsp;",$s);
$s=str_replace(" .warning. ","&nbsp;<img src=\"smiles/warning.gif\" alt=\".warning.\"/>&nbsp;",$s);
$s=str_replace(" .zloi. ","&nbsp;<img src=\"smiles/zloi.gif\" alt=\".zloi.\"/>&nbsp;",$s);
$s=str_replace(" .heart. ","&nbsp;<img src=\"smiles/heart.gif\" alt=\".heart.\"/>&nbsp;",$s);
$s=str_replace(" .talk. ","&nbsp;<img src=\"smiles/talk.gif\" alt=\".talk.\"/>&nbsp;",$s);
$s=str_replace(" .cvetok. ","&nbsp;<img src=\"smiles/cvetok.gif\" alt=\".cvetok.\"/>&nbsp;",$s);
$s=str_replace(" .loveyou. ","&nbsp;<img src=\"smiles/love.you.gif\" alt=\".loveyou.\"/>&nbsp;",$s);
$s=str_replace(" .kruzhka. ","&nbsp;<img src=\"smiles/kruzhka.gif\" alt=\".kruzhka.\"/>&nbsp;",$s);
$s=str_replace(" .4mok. ","&nbsp;<img src=\"smiles/4mok.gif\" alt=\".4mok.\"/>&nbsp;",$s);
$s=str_replace(" .love. ","&nbsp;<img src=\"smiles/love.gif\" alt=\".love.\"/>&nbsp;",$s);
$s=str_replace(" .smoke. ","&nbsp;<img src=\"smiles/smoke.gif\" alt=\".smoke.\"/>&nbsp;",$s);
return dollar($s);
}

function zashita($a){
$str=array(
chr(0) => "",
chr(1) => "",
chr(2) => "",
chr(3) => "",
chr(4) => "",
chr(5) => "",
chr(6) => "",
chr(7) => "",
chr(8) => "",
chr(9) => "",
chr(10) => "",
chr(11) => "",
chr(12) => "",
chr(13) => "",
chr(14) => "",
chr(15) => "",
chr(16) => "",
chr(17) => "",
chr(18) => "",
chr(19) => "",
chr(20) => "",
chr(21) => "",
chr(22) => "",
chr(23) => "",
chr(24) => "",
chr(25) => "",
chr(26) => "",
chr(27) => "",
chr(28) => "",
chr(29) => "",
chr(30) => "",
chr(31) => "",
"#|#"  => "",
"   " => " ",
"  " => " ",
chr(208).chr(144) => "А",
chr(208).chr(145) => "Б",
chr(208).chr(146) => "В",
chr(208).chr(147) => "Г",
chr(208).chr(148) => "Д",
chr(208).chr(149) => "Е",
chr(208).chr(129) => "Ё",
chr(208).chr(150) => "Ж",
chr(208).chr(151) => "З",
chr(208).chr(152) => "И",
chr(208).chr(153) => "Й",
chr(208).chr(154) => "К",
chr(208).chr(155) => "Л",
chr(208).chr(156) => "М",
chr(208).chr(157) => "Н",
chr(208).chr(158) => "О",
chr(208).chr(159) => "П",
chr(208).chr(160) => "Р",
chr(208).chr(161) => "С",
chr(208).chr(162) => "Т",
chr(208).chr(163) => "У",
chr(208).chr(164) => "Ф",
chr(208).chr(165) => "Х",
chr(208).chr(166) => "Ц",
chr(208).chr(167) => "Ч",
chr(208).chr(168) => "Ш",
chr(208).chr(169) => "Щ",
chr(208).chr(170) => "Ъ",
chr(208).chr(171) => "Ы",
chr(208).chr(172) => "Ь",
chr(208).chr(173) => "Э",
chr(208).chr(174) => "Ю",
chr(208).chr(175) => "Я",
chr(208).chr(176) => "а",
chr(208).chr(177) => "б",
chr(208).chr(178) => "в",
chr(208).chr(179) => "г",
chr(208).chr(180) => "д",
chr(208).chr(181) => "е",
chr(209).chr(145) => "ё",
chr(208).chr(182) => "ж",
chr(208).chr(183) => "з",
chr(208).chr(184) => "и",
chr(208).chr(185) => "й",
chr(208).chr(186) => "к",
chr(208).chr(187) => "л",
chr(208).chr(188) => "м",
chr(208).chr(189) => "н",
chr(208).chr(190) => "о",
chr(208).chr(191) => "п",
chr(209).chr(128) => "р",
chr(209).chr(129) => "с",
chr(209).chr(130) => "т",
chr(209).chr(131) => "у",
chr(209).chr(132) => "ф",
chr(209).chr(133) => "х",
chr(209).chr(134) => "ц",
chr(209).chr(135) => "ч",
chr(209).chr(136) => "ш",
chr(209).chr(137) => "щ",
chr(209).chr(138) => "ъ",
chr(209).chr(139) => "ы",
chr(209).chr(140) => "ь",
chr(209).chr(141) => "э",
chr(209).chr(142) => "ю",
chr(209).chr(143) => "я",
);
return stripslashes(strtr($a, $str));
}

function rus($a){
$change=array(
chr(10) => "",
chr(13) => "",
"А"  =>  chr(208).chr(144) ,
"Б"  =>  chr(208).chr(145) ,
"В"  =>  chr(208).chr(146) ,
"Г"  =>  chr(208).chr(147) ,
"Д"  =>  chr(208).chr(148) ,
"Е"  =>  chr(208).chr(149) ,
"Ё"  =>  chr(208).chr(129) ,
"Ж"  =>  chr(208).chr(150) ,
"З"  =>  chr(208).chr(151) ,
"И"  =>  chr(208).chr(152) ,
"Й"  =>  chr(208).chr(153) ,
"К"  =>  chr(208).chr(154) ,
"Л"  =>  chr(208).chr(155) ,
"М"  =>  chr(208).chr(156) ,
"Н"  =>  chr(208).chr(157) ,
"О"  =>  chr(208).chr(158) ,
"П"  =>  chr(208).chr(159) ,
"Р"  =>  chr(208).chr(160) ,
"С"  =>  chr(208).chr(161) ,
"Т"  =>  chr(208).chr(162) ,
"У"  =>  chr(208).chr(163) ,
"Ф"  =>  chr(208).chr(164) ,
"Х"  =>  chr(208).chr(165) ,
"Ц"  =>  chr(208).chr(166) ,
"Ч"  =>  chr(208).chr(167) ,
"Ш"  =>  chr(208).chr(168) ,
"Щ"  =>  chr(208).chr(169) ,
"Ъ"  =>  chr(208).chr(170) ,
"Ы"  =>  chr(208).chr(171) ,
"Ь"  =>  chr(208).chr(172) ,
"Э"  =>  chr(208).chr(173) ,
"Ю"  =>  chr(208).chr(174) ,
"Я"  =>  chr(208).chr(175) ,
"а"  =>  chr(208).chr(176) ,
"б"  =>  chr(208).chr(177) ,
"в"  =>  chr(208).chr(178) ,
"г"  =>  chr(208).chr(179) ,
"д"  =>  chr(208).chr(180) ,
"е"  =>  chr(208).chr(181) ,
"ё"  =>  chr(209).chr(145) ,
"ж"  =>  chr(208).chr(182) ,
"з"  =>  chr(208).chr(183) ,
"и"  =>  chr(208).chr(184) ,
"й"  =>  chr(208).chr(185) ,
"к"  =>  chr(208).chr(186) ,
"л"  =>  chr(208).chr(187) ,
"м"  =>  chr(208).chr(188) ,
"н"  =>  chr(208).chr(189) ,
"о"  =>  chr(208).chr(190) ,
"п"  =>  chr(208).chr(191) ,
"р"  =>  chr(209).chr(128) ,
"с"  =>  chr(209).chr(129) ,
"т"  =>  chr(209).chr(130) ,
"у"  =>  chr(209).chr(131) ,
"ф"  =>  chr(209).chr(132) ,
"х"  =>  chr(209).chr(133) ,
"ц"  =>  chr(209).chr(134) ,
"ч"  =>  chr(209).chr(135) ,
"ш"  =>  chr(209).chr(136) ,
"щ"  =>  chr(209).chr(137) ,
"ъ"  =>  chr(209).chr(138) ,
"ы"  =>  chr(209).chr(139) ,
"ь"  =>  chr(209).chr(140) ,
"э"  =>  chr(209).chr(141) ,
"ю"  =>  chr(209).chr(142) ,
"я"  =>  chr(209).chr(143) ,
chr(128) => "&#x402;",
chr(129) => "&#x403;",
chr(130) => "&#x201A;",
chr(131) => "&#x453;",
chr(132) => "&#x201E;",
chr(133) => "&#x2026;",
chr(134) => "&#x2020;",
chr(135) => "&#x2021;",
chr(136) => "&#x20AC;",
chr(137) => "&#x2030;",
chr(138) => "&#x409;",
chr(139) => "&#x2039;",
chr(140) => "&#x40A;",
chr(141) => "&#x40C;",
chr(142) => "&#x40B;",
chr(143) => "&#x40F;",
chr(144) => "&#x452;",
chr(145) => "&#x2018;",
chr(146) => "&#x2019;",
chr(147) => "&#x201C;",
chr(148) => "&#x201D;",
chr(149) => "&#x2022;",
chr(150) => "-", // "&#x2013;",
chr(151) => "-", // "&#x2014;",
chr(153) => "&#x2122;",
chr(154) => "&#x459;",
chr(155) => "&#x203A;",
chr(156) => "&#x45A;",
chr(157) => "&#x45C;",
chr(158) => "&#x45B;",
chr(159) => "&#x45F;",
chr(160) => "&#xA0;",
chr(161) => "&#x40E;",
chr(162) => "&#x45E;",
chr(163) => "&#x408;",
chr(164) => "&#xA4;",
chr(165) => "&#x490;",
chr(166) => "&#xA6;",
chr(167) => "&#xA7;",
chr(169) => "&#xA9;",
chr(170) => "&#x404;",
chr(171) => "&#xAB;",
chr(172) => "&#xAC;",
chr(173) => "&#xAD;",
chr(174) => "&#xAE;",
chr(175) => "&#x407;",
chr(176) => "&#xB0;",
chr(177) => "&#xB1;",
chr(178) => "&#x406;",
chr(179) => "&#x456;",
chr(180) => "&#x491;",
chr(181) => "&#xB5;",
chr(182) => "&#xB6;",
chr(183) => "&#xB7;",
chr(185) => "&#x2116;",
chr(186) => "&#x454;",
chr(187) => "&#xBB;",
chr(188) => "&#x458;",
chr(189) => "&#x405;",
chr(190) => "&#x455;",
chr(191) => "&#x457;",
"&nbsp;&nbsp;" => "&nbsp;",
"&nbsp; &nbsp;" => "&nbsp;",
);
return strtr($a, $change);
}