Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Gábor Papp
Added: Jun 22, 2018 8:33 AM
Views: 4
Tags: no tags
  1. function isUTF8($string){
  2.     return preg_match('%(?:
  3.    [\xC2-\xDF][\x80-\xBF]        # non-overlong 2-byte
  4.    |\xE0[\xA0-\xBF][\x80-\xBF]               # excluding overlongs
  5.    |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}      # straight 3-byte
  6.    |\xED[\x80-\x9F][\x80-\xBF]               # excluding surrogates
  7.    |\xF0[\x90-\xBF][\x80-\xBF]{2}    # planes 1-3
  8.    |[\xF1-\xF3][\x80-\xBF]{3}                  # planes 4-15
  9.    |\xF4[\x80-\x8F][\x80-\xBF]{2}    # plane 16
  10.    )+%xs', $string);
  11. }
  12.  
  13. function utf8tohun($string) {
  14.         $string=iconv('utf-8','ISO-8859-2',$string);
  15.         return $string;
  16. }
  17. function huntoutf8($string) {
  18.         $string=iconv('ISO-8859-2','utf-8',$string);
  19.         return $string;
  20. }
  21.  
  22. //$tartalom=file_get_contents('../valami.txt');
  23. if (isUTF8($tartalom)==0) {
  24.     $tartalom = huntoutf8($tartalom);
  25. }