XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
transcode_wrapper.php
Go to the documentation of this file.
1 <?php
19 function encode_utf8($string = '', $encoding = 'iso-8859-1', $safe_mode = false)
20 {
21  $safe = ($safe_mode) ? $string : false;
22  if (strtoupper($encoding) == 'UTF-8' || strtoupper($encoding) == 'UTF8') {
23  return $string;
24  } elseif (strtoupper($encoding) == 'ISO-8859-1') {
25  return utf8_encode($string);
26  } elseif (strtoupper($encoding) == 'WINDOWS-1252') {
27  return utf8_encode(map_w1252_iso8859_1($string));
28  } elseif (strtoupper($encoding) == 'UNICODE-1-1-UTF-7') {
29  $encoding = 'utf-7';
30  }
31  if (function_exists('mb_convert_encoding')) {
32  $conv = @mb_convert_encoding($string, 'UTF-8', strtoupper($encoding));
33  if ($conv) return $conv;
34  }
35  if (function_exists('iconv')) {
36  $conv = @iconv(strtoupper($encoding), 'UTF-8', $string);
37  if ($conv) return $conv;
38  }
39  if (function_exists('libiconv')) {
40  $conv = @libiconv(strtoupper($encoding), 'UTF-8', $string);
41  if ($conv) return $conv;
42  }
43  return $safe;
44 }
45 
55 function decode_utf8($string = '', $encoding = 'iso-8859-1', $safe_mode = false)
56 {
57  $safe = ($safe_mode) ? $string : false;
58  if (!$encoding) $encoding = 'ISO-8859-1';
59  if (strtoupper($encoding) == 'UTF-8' || strtoupper($encoding) == 'UTF8') {
60  return $string;
61  } elseif (strtoupper($encoding) == 'ISO-8859-1') {
62  return utf8_decode($string);
63  } elseif (strtoupper($encoding) == 'WINDOWS-1252') {
64  return map_iso8859_1_w1252(utf8_decode($string));
65  } elseif (strtoupper($encoding) == 'UNICODE-1-1-UTF-7') {
66  $encoding = 'utf-7';
67  }
68  if (function_exists('mb_convert_encoding')) {
69  $conv = @mb_convert_encoding($string, strtoupper($encoding), 'UTF-8');
70  if ($conv) return $conv;
71  }
72  if (function_exists('iconv')) {
73  $conv = @iconv('UTF-8', strtoupper($encoding), $string);
74  if ($conv) return $conv;
75  }
76  if (function_exists('libiconv')) {
77  $conv = @libiconv('UTF-8', strtoupper($encoding), $string);
78  if ($conv) return $conv;
79  }
80  return $safe;
81 }
82 
90 function map_w1252_iso8859_1($string = '')
91 {
92  if ($string == '') return '';
93  $return = '';
94  for ($i = 0; $i < strlen($string); ++$i) {
95  $c = ord($string{$i});
96  switch ($c) {
97  case 129: $return .= chr(252); break;
98  case 132: $return .= chr(228); break;
99  case 142: $return .= chr(196); break;
100  case 148: $return .= chr(246); break;
101  case 153: $return .= chr(214); break;
102  case 154: $return .= chr(220); break;
103  case 225: $return .= chr(223); break;
104  default: $return .= chr($c); break;
105  }
106  }
107  return $return;
108 }
109 
117 function map_iso8859_1_w1252($string = '')
118 {
119  if ($string == '') return '';
120  $return = '';
121  for ($i = 0; $i < strlen($string); ++$i) {
122  $c = ord($string{$i});
123  switch ($c) {
124  case 196: $return .= chr(142); break;
125  case 214: $return .= chr(153); break;
126  case 220: $return .= chr(154); break;
127  case 223: $return .= chr(225); break;
128  case 228: $return .= chr(132); break;
129  case 246: $return .= chr(148); break;
130  case 252: $return .= chr(129); break;
131  default: $return .= chr($c); break;
132  }
133  }
134  return $return;
135 }
136 
137 ?>
map_w1252_iso8859_1($string= '')
map_iso8859_1_w1252($string= '')
decode_utf8($string= '', $encoding= 'iso-8859-1', $safe_mode=false)
encode_utf8($string= '', $encoding= 'iso-8859-1', $safe_mode=false)