0

I was wondering if it is possible to somehow detect what encode type text is using for example if there is word "Šanęrt", it's UTF-8 and if it's "Projekto UžduoÄ•ių Ataskaita" would write what encode it is. Because my site creates PDF file, and I can't find why it writes ž - these symbols and not letters.

And I think, if I could find out what encode it is I could decode to UTF-8 to write normally. For example if it is UžduoÄ•ių, normal it would be - Užduočių. Here is the simple code:

$pdf->ezText("\n" . $AppUI->_('Project Completed Task Report'), 12);

When locale set to Lithuanian it writes Pabaigto Projekto Užduoĕių Ataskaita.

halfer
  • 19,824
  • 17
  • 99
  • 186
McLaren
  • 776
  • 1
  • 10
  • 23
  • _i was wondering if it is possible to somehow detect what encode type text is using_ Technically yes, there is a method for that: http://php.net/manual/en/function.mb-detect-encoding.php . Did you try it already? – briosheje Jul 20 '15 at 10:43

2 Answers2

1

use the below procedure :

<?php
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
$ary[] = "UTF-8";
echo mb_detect_encoding($str, $ary);

?>

The thing in $ary[] is that we need to provide the names of encoding to check against it.

Edited:

<?php

    $ary[] = "ASCII";
    $ary[] = "JIS";
    $ary[] = "EUC-JP";
    $ary[] = "UTF-8";
    foreach( $ary as $ar )
    {
      $check = mb_detect_encoding($str, $ar);
        if($check)
        {
          die("Your Encoding is:".$ar);
        }
    }

?>

Whenever you're encoding will be encountered it will die there to show your encoding type.

Link: http://php.net/manual/en/function.mb-detect-encoding.php

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
  • Can you help me, because when i use this it writes that it is UTF-8. But why it is symbols then? How to fix this? – McLaren Jul 20 '15 at 10:49
0

You can use function iconv_get_encoding($str) to get encoding from string

http://php.net/manual/pl/function.iconv-get-encoding.php

You may be interested also in this and this

Community
  • 1
  • 1
Robert
  • 19,800
  • 5
  • 55
  • 85