summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xml.class10
1 files changed, 10 insertions, 0 deletions
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 = '<?xml version="1.0" encoding="' . $this->_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 = '<?xml version="1.0" encoding="' . $this->_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));