From 7fb28fd960cd309a84fc74f390460503ab8c7810 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Mon, 19 Mar 2007 11:17:29 +0000 Subject: Prepend XML header for charset detection in PHP5 --- xml.class | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xml.class b/xml.class index f61793f..36aa165 100644 --- a/xml.class +++ b/xml.class @@ -60,6 +60,11 @@ function from_xml($xmldata, $p) if (is_resource($xmldata)) { + if (!preg_match('/^<\?xml/', ($head = fread($xmldata, 1024 * 1024)))) # Prepend XML header for charset detection in PHP5 + $head = '_p['encoding'] . '"?>' . $head; + + $result = xml_parse($parser, $head, false); + while ($result && !feof($xmldata)) $result = xml_parse($parser, fread($xmldata, 1024 * 1024), false); @@ -67,7 +72,12 @@ function from_xml($xmldata, $p) $result = xml_parse($parser, "", true); } else + { + if (!preg_match('/^<\?xml/', $xmldata)) # Prepend XML header for charset detection in PHP5 + $xmldata = '_p['encoding'] . '"?>' . $xmldata; + $result = xml_parse($parser, $xmldata); + } if (!$result) $this->error .= sprintf("it_xml error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); -- cgit v1.2.3