summaryrefslogtreecommitdiff
path: root/includes/common.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/common.inc')
-rw-r--r--includes/common.inc28
1 files changed, 28 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 304e753ca..2eae306cb 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -835,6 +835,34 @@ function drupal_page_footer() {
module_invoke_all("exit");
}
+/**
+ * Wrapper around xml_parser_create() which extracts the encoding from the XML
+ * data first and sets the output encoding to UTF-8. This function should be
+ * used instead of xml_parser_create(), because PHP's XML parser doesn't check
+ * the input encoding itself.
+ *
+ * This is also where unsupported encodings should be converted.
+ * Callers should take this into account: $data might have been changed after
+ * the call.
+ *
+ * @param $data The XML data which will be parsed later.
+ */
+function drupal_xml_parser_create(&$data) {
+ $encoding = 'utf-8';
+ if (ereg('^<\?xml[^>]+encoding="([^"]+)"', $data, $match)) {
+ $encoding = $match[1];
+ }
+
+ /*
+ * Note: unsupported encodings will need to be converted here into UTF-8,
+ * and $encoding set to 'utf-8'.
+ */
+
+ $xml_parser = xml_parser_create($encoding);
+ xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'utf-8');
+ return $xml_parser;
+}
+
include_once "includes/theme.inc";
include_once "includes/pager.inc";
include_once "includes/menu.inc";