Convert UTF8 to Windows-1251


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function utf8_to_win($string){
  2. for ($c=0;$c<strlen($string);$c++){
  3. $i=ord($string[$c]);
  4. if ($i <= 127) @$out .= $string[$c];
  5. if (@$byte2){
  6. $new_c2=($c1&3)*64+($i&63);
  7. $new_c1=($c1>>2)&5;
  8. $new_i=$new_c1*256+$new_c2;
  9. if ($new_i==1025){
  10. $out_i=168;
  11. } else {
  12. if ($new_i==1105){
  13. $out_i=184;
  14. } else {
  15. $out_i=$new_i-848;
  16. }
  17. }
  18. @$out .= chr($out_i);
  19. $byte2 = false;
  20. }
  21. if (($i>>5)==6) {
  22. $c1 = $i;
  23. $byte2 = true;
  24. }
  25. }
  26. return $out;
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.