29 'US-ASCII' => array(
'ISO-8859-1',
'ISO-8859-2',
'ISO-8859-3',
'ISO-8859-4',
30 'ISO-8859-5',
'ISO-8859-6',
'ISO-8859-7',
'ISO-8859-8',
31 'ISO-8859-9',
'ISO-8859-10',
'ISO-8859-11',
'ISO-8859-12',
32 'ISO-8859-13',
'ISO-8859-14',
'ISO-8859-15',
'UTF-8',
33 'EUC-JP',
'EUC-',
'EUC-KR',
'EUC-CN',),
45 if (self::$instance ===
null) {
46 self::$instance =
new self();
52 private function __construct()
54 for ($i = 0; $i < 32; $i++) {
55 $this->xml_iso88591_Entities[
"in"][] = chr($i);
56 $this->xml_iso88591_Entities[
"out"][] =
"&#{$i};";
59 for ($i = 160; $i < 256; $i++) {
60 $this->xml_iso88591_Entities[
"in"][] = chr($i);
61 $this->xml_iso88591_Entities[
"out"][] =
"&#{$i};";
92 if ($srcEncoding ==
'') {
97 switch (strtoupper($srcEncoding .
'_' . $destEncoding)) {
99 case 'ISO-8859-1_US-ASCII':
100 $escapedData = str_replace(array(
'&',
'"',
"'",
'<',
'>'), array(
'&',
'"',
''',
'<',
'>'), $data);
101 $escapedData = str_replace($this->xml_iso88591_Entities[
'in'], $this->xml_iso88591_Entities[
'out'], $escapedData);
103 case 'ISO-8859-1_UTF-8':
104 $escapedData = str_replace(array(
'&',
'"',
"'",
'<',
'>'), array(
'&',
'"',
''',
'<',
'>'), $data);
105 $escapedData = utf8_encode($escapedData);
107 case 'ISO-8859-1_ISO-8859-1':
108 case 'US-ASCII_US-ASCII':
109 case 'US-ASCII_UTF-8':
111 case 'US-ASCII_ISO-8859-1':
114 $escapedData = str_replace(array(
'&',
'"',
"'",
'<',
'>'), array(
'&',
'"',
''',
'<',
'>'), $data);
117 case 'UTF-8_US-ASCII':
118 case 'UTF-8_ISO-8859-1':
122 $data = (string)$data;
124 for ($nn = 0; $nn < $ns; $nn++) {
132 $escapedData .=
'"';
135 $escapedData .=
'&';
138 $escapedData .=
''';
141 $escapedData .=
'<';
144 $escapedData .=
'>';
150 elseif ($ii >> 5 == 6) {
152 $ii = ord($data[$nn + 1]);
154 $ii = ($b1 * 64) + $b2;
155 $ent = sprintf(
'&#%d;', $ii);
156 $escapedData .= $ent;
159 elseif ($ii >> 4 == 14) {
161 $ii = ord($data[$nn + 1]);
163 $ii = ord($data[$nn + 2]);
165 $ii = ((($b1 * 64) + $b2) * 64) + $b3;
166 $ent = sprintf(
'&#%d;', $ii);
167 $escapedData .= $ent;
170 elseif ($ii >> 3 == 30) {
172 $ii = ord($data[$nn + 1]);
174 $ii = ord($data[$nn + 2]);
176 $ii = ord($data[$nn + 3]);
178 $ii = ((((($b1 * 64) + $b2) * 64) + $b3) * 64) + $b4;
179 $ent = sprintf(
'&#%d;', $ii);
180 $escapedData .= $ent;
206 error_log(
'XML-RPC: ' . __METHOD__ .
": Converting from $srcEncoding to $destEncoding: not supported...");
223 if (is_string($validList)) {
224 $validList = explode(
',', $validList);
226 if (@in_array(strtoupper($encoding), $validList)) {
229 if (array_key_exists($encoding, $this->charset_supersets)) {
230 foreach ($validList as $allowed) {
231 if (in_array($allowed, $this->charset_supersets[$encoding])) {
258 throw new \Exception(
'Unsupported charset: ' . $charset);