Blame view

vendor/yiisoft/multiparser/Encoder.php 1.43 KB
e91188dd   Mihail   add Encoder class
1
2
3
4
5
6
7
8
  <?php
  /**
   * Created by PhpStorm.
   * User: Cibermag
   * Date: 27.08.2015
   * Time: 13:36
   */
  
74072a2a   Mihail   add first version...
9
  namespace yii\multiparser;
e91188dd   Mihail   add Encoder class
10
11
12
13
  
  // @todo add comments
  class Encoder
  {
40ff24a1   Mihail   refactor CsvParse...
14
15
16
17
      /** @var out encoding charset */
      public static $out_charset = 'UTF-8';
      /** @var out encoding charset */
      public static $in_charset = 'windows-1251';
e91188dd   Mihail   add Encoder class
18
19
20
21
22
23
24
25
26
27
28
  
      public static function encodeFile($in_charset, $out_charset, $filePath)
      {
  
          $old_content = file_get_contents($filePath);
          $encode_content = self::encode( $in_charset, $out_charset, $old_content );
          $file = @fopen($filePath, "w");
          fwrite($file, $encode_content);
          @fclose($file);
      }
  
74072a2a   Mihail   add first version...
29
      public static function encodeArray( $array, $in_charset = '', $out_charset = '')
e91188dd   Mihail   add Encoder class
30
      {
74072a2a   Mihail   add first version...
31
32
          if (isset($in_charset))
          self::$in_charset = isset($in_charset);
e91188dd   Mihail   add Encoder class
33
  
74072a2a   Mihail   add first version...
34
          if (isset($out_charset))
e91188dd   Mihail   add Encoder class
35
36
37
38
39
          self::$out_charset = $out_charset;
  
          $result = array_map(
              function ( $array) {
  
74072a2a   Mihail   add first version...
40
                  return self::encodeString( $array, self::$in_charset, self::$out_charset );
e91188dd   Mihail   add Encoder class
41
42
43
44
45
46
47
  
              },
              $array);
  
          return $result;
      }
  
74072a2a   Mihail   add first version...
48
      public static function encodeString( $source, $in_charset = '', $out_charset = '' ){
e91188dd   Mihail   add Encoder class
49
  
74072a2a   Mihail   add first version...
50
51
52
53
54
55
56
          if (isset($in_charset))
              self::$in_charset = isset($in_charset);
  
          if (isset($out_charset))
              self::$out_charset = $out_charset;
  
          return iconv( self::$in_charset, self::$out_charset, $source );
e91188dd   Mihail   add Encoder class
57
58
59
  
      }
  }