Jump to content
php.lv forumi

Noņemt "function win_to_utf($str)" un function utf_to_win


ppc
 Share

Recommended Posts

Man vajag noņemt win_to_utf un utf_to_win funkciju, lai darbojas tikai utf-8. Var kāds palīdzēt?

 

function rus_to_k($str) {
$str = str_replace("а","a",$str);
$str = str_replace("б","b",$str);
$str = str_replace("в","v",$str);
$str = str_replace("г","g",$str);
$str = str_replace("д","d",$str);
$str = str_replace("е","e",$str);
$str = str_replace("ё","e",$str);
$str = str_replace("ж","j",$str);
$str = str_replace("з","z",$str);
$str = str_replace("и","i",$str);
$str = str_replace("й","y",$str);
$str = str_replace("к","k",$str);
$str = str_replace("л","l",$str);
$str = str_replace("м","m",$str);
$str = str_replace("н","n",$str);
$str = str_replace("о","o",$str);
$str = str_replace("п","p",$str);
$str = str_replace("р","r",$str);
$str = str_replace("с","s",$str);
$str = str_replace("т","t",$str);
$str = str_replace("у","u",$str);
$str = str_replace("ф","f",$str);
$str = str_replace("х","h",$str);
$str = str_replace("ч","c",$str);
$str = str_replace("ц","q",$str);
$str = str_replace("ш","w",$str);
$str = str_replace("щ",">",$str);
$str = str_replace("ь","<",$str);
$str = str_replace("ы","x",$str);
$str = str_replace("ъ",".",$str);
$str = str_replace("э",":",$str);
$str = str_replace("ю",";",$str);
$str = str_replace("я","}",$str);
$str = str_replace("А","a",$str);
$str = str_replace("Б","b",$str);
$str = str_replace("В","v",$str);
$str = str_replace("Г","g",$str);
$str = str_replace("Д","d",$str);
$str = str_replace("Е","e",$str);
$str = str_replace("Ё","e",$str);
$str = str_replace("Ж","j",$str);
$str = str_replace("З","z",$str);
$str = str_replace("И","i",$str);
$str = str_replace("Й","y",$str);
$str = str_replace("К","k",$str);
$str = str_replace("Л","l",$str);
$str = str_replace("М","m",$str);
$str = str_replace("Н","n",$str);
$str = str_replace("О","o",$str);
$str = str_replace("П","p",$str);
$str = str_replace("Р","r",$str);
$str = str_replace("С","s",$str);
$str = str_replace("Т","t",$str);
$str = str_replace("У","u",$str);
$str = str_replace("Ф","f",$str);
$str = str_replace("Х","h",$str);
$str = str_replace("Ч","c",$str);
$str = str_replace("Ц","q",$str);
$str = str_replace("Ш","w",$str);
$str = str_replace("Щ",">",$str);
$str = str_replace("Ь","<",$str);
$str = str_replace("Ы","x",$str);
$str = str_replace("Ъ",".",$str);
$str = str_replace("Э",":",$str);
$str = str_replace("Ю",";",$str);
$str = str_replace("Я","}",$str);
return $str;
}
function win_to_utf($str) {
if (function_exists('mb_convert_encoding')) return mb_convert_encoding($str, 'utf-8', 'windows-1251');
if (function_exists('iconv')) return iconv('windows-1251', 'utf-8', $str);
$win1251utf8 = array(
"\xC0"=>"А","\xC1"=>"Б","\xC2"=>"В","\xC3"=>"Г","\xC4"=>"Д","\xC5"=>"Е","\xA8"=>"Ё","\xC6"=>"Ж","\xC7"=>"З","\xC8"=>"И","\xC9"=>"Й","\xCA"=>"К","\xCB"=>"Л","\xCC"=>"М",
"\xCD"=>"Н","\xCE"=>"О","\xCF"=>"П","\xD0"=>"Р","\xD1"=>"С","\xD2"=>"Т","\xD3"=>"У","\xD4"=>"Ф","\xD5"=>"Х","\xD6"=>"Ц","\xD7"=>"Ч","\xD8"=>"Ш","\xD9"=>"Щ","\xDA"=>"Ъ",
"\xDB"=>"Ы","\xDC"=>"Ь","\xDD"=>"Э","\xDE"=>"Ю","\xDF"=>"Я","\xE0"=>"а","\xE1"=>"б","\xE2"=>"в","\xE3"=>"г","\xE4"=>"д","\xE5"=>"е","\xB8"=>"ё","\xE6"=>"ж","\xE7"=>"з",
"\xE8"=>"и","\xE9"=>"й","\xEA"=>"к","\xEB"=>"л","\xEC"=>"м","\xED"=>"н","\xEE"=>"о","\xEF"=>"п","\xF0"=>"р","\xF1"=>"с","\xF2"=>"т","\xF3"=>"у","\xF4"=>"ф","\xF5"=>"х",
"\xF6"=>"ц","\xF7"=>"ч","\xF8"=>"ш","\xF9"=>"щ","\xFA"=>"ъ","\xFB"=>"ы","\xFC"=>"ь","\xFD"=>"э","\xFE"=>"ю","\xFF"=>"я");
return strtr($str, $win1251utf8);
}
function utf_to_win($str) {
if (function_exists('mb_convert_encoding')) return mb_convert_encoding($str, 'windows-1251', 'utf-8');
if (function_exists('iconv')) return iconv('utf-8', 'windows-1251', $str);
$utf8win1251 = array(
"А"=>"\xC0","Б"=>"\xC1","В"=>"\xC2","Г"=>"\xC3","Д"=>"\xC4","Е"=>"\xC5","Ё"=>"\xA8","Ж"=>"\xC6","З"=>"\xC7","И"=>"\xC8","Й"=>"\xC9","К"=>"\xCA","Л"=>"\xCB","М"=>"\xCC",
"Н"=>"\xCD","О"=>"\xCE","П"=>"\xCF","Р"=>"\xD0","С"=>"\xD1","Т"=>"\xD2","У"=>"\xD3","Ф"=>"\xD4","Х"=>"\xD5","Ц"=>"\xD6","Ч"=>"\xD7","Ш"=>"\xD8","Щ"=>"\xD9","Ъ"=>"\xDA",
"Ы"=>"\xDB","Ь"=>"\xDC","Э"=>"\xDD","Ю"=>"\xDE","Я"=>"\xDF","а"=>"\xE0","б"=>"\xE1","в"=>"\xE2","г"=>"\xE3","д"=>"\xE4","е"=>"\xE5","ё"=>"\xB8","ж"=>"\xE6","з"=>"\xE7",
"и"=>"\xE8","й"=>"\xE9","к"=>"\xEA","л"=>"\xEB","м"=>"\xEC","н"=>"\xED","о"=>"\xEE","п"=>"\xEF","р"=>"\xF0","с"=>"\xF1","т"=>"\xF2","у"=>"\xF3","ф"=>"\xF4","х"=>"\xF5",
"ц"=>"\xF6","ч"=>"\xF7","ш"=>"\xF8","щ"=>"\xF9","ъ"=>"\xFA","ы"=>"\xFB","ь"=>"\xFC","э"=>"\xFD","ю"=>"\xFE","я"=>"\xFF");
return strtr($str, $utf8win1251);
}
function trun_to_rus($str) {
$str = str_replace("ch","ч",$str);
$str = str_replace("sc","щ",$str);
$str = str_replace("sh","ш",$str);
$str = str_replace("ye","э",$str);
$str = str_replace("yu","ю",$str);
$str = str_replace("ya","я",$str);
$str = str_replace("CH","Ч",$str);
$str = str_replace("Ch","Ч",$str);
$str = str_replace("SC","Щ",$str);
$str = str_replace("Sc","Щ",$str);
$str = str_replace("SH","Ш",$str);
$str = str_replace("Sh","Ш",$str);
$str = str_replace("""","Ъ",$str);
$str = str_replace(""","ъ",$str);
$str = str_replace("‘‘","Ь",$str);
$str = str_replace("‘","ь",$str);
$str = str_replace("YE","Э",$str);
$str = str_replace("Ye","Э",$str);
$str = str_replace("YU","Ю",$str);
$str = str_replace("Yu","Ю",$str);
$str = str_replace("YA","Я",$str);
$str = str_replace("Ya","Я",$str);
$str = strtr($str,array("\""=>"","a"=>"а","b"=>"б","v"=>"в","g"=>"г","d"=>"д","e"=>"е","j"=>"ж","z"=>"з","i"=>"и","y"=>"й","k"=>"к","l"=>"л","m"=>"м","n"=>"н","o"=>"о","p"=>"п","r"=>"р","s"=>"с","t"=>"т","u"=>"у","f"=>"ф","h"=>"х","c"=>"ц","w"=>"ш","x"=>"ы","A"=>"А","B"=>"Б","V"=>"В","G"=>"Г","D"=>"Д","E"=>"Е","J"=>"Ж","Z"=>"З","I"=>"И","Y"=>"Й","K"=>"К","L"=>"Л","M"=>"М","N"=>"Н","O"=>"О","P"=>"П","R"=>"Р","S"=>"С","T"=>"Т","U"=>"У","F"=>"Ф","H"=>"Х","C"=>"Ц","W"=>"Ш","X"=>"Ы"));
return $str;
}
function check($message) {
$message = htmlspecialchars($message);
$message = str_replace("\r\n", "<br/>", $message);
$message = strtr($message, 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") => ""));
$message = iconv('utf-8', 'windows-1251', $message);
$message = mb_substr($message, 0, 1000, 'UTF8');
$message = iconv('windows-1251', 'utf-8', $message);
$message = str_replace("'","'",$message);
$message = str_replace("\"",""",$message);
$message = str_replace("\$","$",$message);
$message = str_replace("$","$",$message);
$message = str_replace("\\","\", $message);
$message = str_replace("`","`", $message);
$message = str_replace("^","^", $message);
$message = str_replace("%","%", $message);
$message = str_replace(":",":",$message);
$message = preg_replace("|:|",":",$message,3);
$message = stripslashes(trim($message));
return $message;
}
function replace_rus($str) {
           	$str = str_replace("а","|",$str);
           	$str = str_replace("б","|",$str);
           	$str = str_replace("в","|",$str);
           	$str = str_replace("г","|",$str);
           	$str = str_replace("д","|",$str);
           	$str = str_replace("е","|",$str);
           	$str = str_replace("ё","|",$str);
           	$str = str_replace("ж","|",$str);
           	$str = str_replace("з","|",$str);
           	$str = str_replace("и","|",$str);
           	$str = str_replace("й","|",$str);
           	$str = str_replace("к","|",$str);
           	$str = str_replace("л","|",$str);
           	$str = str_replace("м","|",$str);
           	$str = str_replace("н","|",$str);
           	$str = str_replace("о","|",$str);
           	$str = str_replace("п","|",$str);
           	$str = str_replace("р","|",$str);
           	$str = str_replace("с","|",$str);
           	$str = str_replace("т","|",$str);
           	$str = str_replace("у","|",$str);
           	$str = str_replace("ф","|",$str);
           	$str = str_replace("х","|",$str);
           	$str = str_replace("ч","|",$str);
           	$str = str_replace("ц","|",$str);
           	$str = str_replace("ш","|",$str);
           	$str = str_replace("щ","|",$str);
           	$str = str_replace("ь","|",$str);
           	$str = str_replace("ы","|",$str);
           	$str = str_replace("ъ","|",$str);
           	$str = str_replace("э","|",$str);
           	$str = str_replace("ю","|",$str);
           	$str = str_replace("я","|",$str);
           	$str = str_replace("А","|",$str);
           	$str = str_replace("Б","|",$str);
           	$str = str_replace("В","|",$str);
           	$str = str_replace("Г","|",$str);
           	$str = str_replace("Д","|",$str);
           	$str = str_replace("Е","|",$str);
           	$str = str_replace("Ё","|",$str);
           	$str = str_replace("Ж","|",$str);
           	$str = str_replace("З","|",$str);
           	$str = str_replace("?","|",$str);
           	$str = str_replace("Й","|",$str);
           	$str = str_replace("К","|",$str);
           	$str = str_replace("Л","|",$str);
           	$str = str_replace("М","|",$str);
           	$str = str_replace("Н","|",$str);
           	$str = str_replace("О","|",$str);
           	$str = str_replace("П","|",$str);
           	$str = str_replace("Р","|",$str);
           	$str = str_replace("С","|",$str);
           	$str = str_replace("Т","|",$str);
           	$str = str_replace("У","|",$str);
           	$str = str_replace("Ф","|",$str);
           	$str = str_replace("Х","|",$str);
           	$str = str_replace("Ч","|",$str);
           	$str = str_replace("Ц","|",$str);
           	$str = str_replace("Ш","|",$str);
           	$str = str_replace("Щ","|",$str);
           	$str = str_replace("Ь","|",$str);
           	$str = str_replace("Ы","|",$str);
           	$str = str_replace("Ъ","|",$str);
           	$str = str_replace("Э","|",$str);
           	$str = str_replace("Ю","|",$str);
           	$str = str_replace("Я","|",$str);
           	return $str;
           	}

Edited by ppc
Link to comment
Share on other sites

Nu tavā vietā jau cits viņu nepārtaisīs.Bet recepte vienkārša:

1. Atrast failu,kurā tiek izsauktas šīs teksta apstrādes funkcijas.

2. Sākumā atslēgt visas.Tur ir daudz kā lieka.Nokomentē attiecīgās vietas ar // vai /* */

3. Debugojot pieslēgt atpakaļ tikai to,ko tiešām vajag.

? garumzīmju vietā var būt vairāki iemesli.Par to var atrast tepat forumā: "Neliels tēmu apkopojums no arhīva sadaļas" -> "Teksta kodējumi (encoding,charset)"

Link to comment
Share on other sites

Nu tavā vietā jau cits viņu nepārtaisīs.Bet recepte vienkārša:

1. Atrast failu,kurā tiek izsauktas šīs teksta apstrādes funkcijas.

2. Sākumā atslēgt visas.Tur ir daudz kā lieka.Nokomentē attiecīgās vietas ar // vai /* */

3. Debugojot pieslēgt atpakaļ tikai to,ko tiešām vajag.

? garumzīmju vietā var būt vairāki iemesli.Par to var atrast tepat forumā: "Neliels tēmu apkopojums no arhīva sadaļas" -> "Teksta kodējumi (encoding,charset)"

 

Tu varētu pārtaisīt? Pilnīgi visu to translīta kodu. Un cik prasīsi par darbu

Link to comment
Share on other sites

Varētu,bet es to nedarīšu arī par naudu.Šis skripts ļoti atgādina wapčatus,kādi tapa Krievijā ap 2006. gadu,un,ja manas aizdomas ir pareizas,tad vienkāršāk tos brīnumus ir uzrakstīt no nulles,nekā kaut ko tur labot.Turklāt viņu kods nav īsti tāds, no kura arī kaut ko varētu mācīties vai ņemt piemēru.Bet ja tomēr tev ir vēlme kaut ko darīt,tad sāc ar pamatiem,un jau visai drīz tev šāds uzdevums nesagādās ne mazākās grūtības.Ja nevēlies mācīties pamatus,tad ieteikums mest mieru,vai rēķināties ar attiecīgām projekta izmaksām + to izklāstīt darba sludinājumā.

Link to comment
Share on other sites

Varētu,bet es to nedarīšu arī par naudu.Šis skripts ļoti atgādina wapčatus,kādi tapa Krievijā ap 2006. gadu,un,ja manas aizdomas ir pareizas,tad vienkāršāk tos brīnumus ir uzrakstīt no nulles,nekā kaut ko tur labot.Turklāt viņu kods nav īsti tāds, no kura arī kaut ko varētu mācīties vai ņemt piemēru.Bet ja tomēr tev ir vēlme kaut ko darīt,tad sāc ar pamatiem,un jau visai drīz tev šāds uzdevums nesagādās ne mazākās grūtības.Ja nevēlies mācīties pamatus,tad ieteikums mest mieru,vai rēķināties ar attiecīgām projekta izmaksām + to izklāstīt darba sludinājumā.

Paldies. vnk varēji pateikt, kad esi nacionālists ar to r pietiktu. )))

Link to comment
Share on other sites

Tieši tā-ar nacionālismu tur nav nekāda sakara.Spriežot pēc ieliktā koda fragmenta,tas ir viens no daudzo čatu un forumu saimes,kuri bija ļoti populāri Krievijā vēl php 4 ziedu laikos.Viņus tolaik rakstīja pārsvarā studenti pašu priekam un biznesiņam,atbilstoši tā laika izpratnei,un lielākoties šo kodu atceros kā neformatētu un bakslašotu wml/html vienā putrā ar php,dīvainiem variabļu nosaukumiem,nebeidzamiem elseif un funkcijām tādā stilā,kā tevis ieliktā.Var jau būt ka šis nav no tiem,bet tad skripta izcelsmi studijā,un varbūt kādam iespējamajam palīdzetājam būs prāts mierīgs,zinot ar ko ir vai nav jārēķinās :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...