note 56299 added to function.convert-cyr-string

From: Date: Tue, 30 Aug 2005 05:52:22 +0000
Subject: note 56299 added to function.convert-cyr-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-94365@lists.php.net to get a copy of this message
//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"; } ---- Manual Page -- http://www.php.net/manual/en/function.convert-cyr-string.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56299 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56299&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56299&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56299&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56299&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56299&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56299&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56299&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94365) next »