summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2007-03-19 11:17:29 +0000
committerChristian Schneider2007-03-19 11:17:29 +0000
commit7fb28fd960cd309a84fc74f390460503ab8c7810 (patch)
tree56d8c157a5e71f1e4c3370012d495e0c256c2a24
parenta282abd3b5b42b948e5ac7a8debdd59f381c7867 (diff)
downloaditools-7fb28fd960cd309a84fc74f390460503ab8c7810.tar.gz
itools-7fb28fd960cd309a84fc74f390460503ab8c7810.tar.bz2
itools-7fb28fd960cd309a84fc74f390460503ab8c7810.zip
Prepend XML header for charset detection in PHP5
-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));