note 56299 deleted from function.convert-cyr-string by mazzanet

From: Date: Tue, 30 Aug 2005 10:25:08 +0000
Subject: note 56299 deleted from function.convert-cyr-string by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94381@lists.php.net to get a copy of this message
Note Submitter: webmaster at chassidus dot ru ---- //And the last stuff: //This function tries to say what is the source encoding of the string //It's can be a matter - when you put same text in form - the coding of text is depend on code-page of you explorer window. //I.e. if your Explorer set to Win-1251 and you put text in Hebrew - is the Hebrew text is coded in unicode; //but if your Explorer set to utf-8 - the text is coded in utf-8 //ô-öèÿ, ïûòàþùàÿñÿ îïðåäåëèòü, ÷òî ïåðåä íàìè // åñëè ýòî utf-8, òî ïî÷òè ïîëîâèíà ñèìâîëîâ áóäåò // chr(215) äëÿ èâðèòà, èëè 208-209 äëÿ ðóññêîãî ÿçûêà function smart_code_page($str,$lng) { $count_rus_utf=0; $count_heb_utf=0; $count_unicode=0; $count_other=0; for($i=0, $m=strlen($str); $i<$m; $i++) { $c=ord($str[$i]); $t .= "[" . $str[$i] . "=" . "$c]"; switch ($c) { case 215: $count_heb_utf +=1; break; case 208: case 209: $count_rus_utf +=1; break; case ord('&'): case ord('#'): case ord(';'): $count_unicode +=1; break; default: $count_other +=1; break; } } echo "$str: count:$m; unicode: $count_unicode; heb utf:$count_heb_utf; rus utf: $count_rus_utf; other: $count_other<br>"; echo "$t<br><br>"; if ($count_unicode*3>$m) echo "it's $lng unicode!<br><br>"; elseif (($count_heb_utf+$count_rus_utf)*3<$m) echo "it's $lng!<br><br>"; elseif (($count_heb_utf)*3>$m) echo "it's utf-8 heb!<br><br>"; elseif (($count_rus_utf)*3>$m) echo "it's utf-8 rus!<br><br>"; elseif (($count_rus_utf+$count_heb_utf)*3>$m) echo "it's utf-8 heb-rus!<br><br>"; else "don't know"; }

« previous php.notes (#94381) next »