+\r
+ // 'guestimate' encoding\r
+ $val_encoding = guess_encoding('', $xml_val);\r
+\r
+ // Since parsing will fail if charset is not specified in the xml prologue,\r
+ // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...\r
+ // The following code might be better for mb_string enabled installs, but\r
+ // makes the lib about 200% slower...\r
+ //if (!is_valid_charset($val_encoding, array('UTF-8')))\r
+ if (!in_array($val_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($xml_val)) {\r
+ if ($val_encoding == 'ISO-8859-1') {\r
+ $xml_val = utf8_encode($xml_val);\r
+ } else {\r
+ if (extension_loaded('mbstring')) {\r
+ $xml_val = mb_convert_encoding($xml_val, 'UTF-8', $val_encoding);\r
+ } else {\r
+ error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $val_encoding);\r
+ }\r
+ }\r
+ }\r
+\r