Blame view

backend/components/parsers/Encoder.php 1.06 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
   */
  
dc10d651   Mihail   add value filter ...
9
  namespace backend\components;
e91188dd   Mihail   add Encoder class
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  
  // @todo add comments
  class Encoder
  {
      public static $in_charset;
      public static $out_charset;
  
  
      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);
      }
  
      public static function encodeArray($in_charset, $out_charset, $array)
      {
  
          self::$in_charset = $in_charset;
          self::$out_charset = $out_charset;
  
          $result = array_map(
              function ( $array) {
  
                  return self::encode( self::$in_charset, self::$out_charset, $array );
  
              },
              $array);
  
          return $result;
      }
  
      private static function encode( $in_charset, $out_charset, $source ){
  
          return iconv($in_charset, $out_charset, $source);
  
      }
  }