diff options
author | Christian Schneider | 2007-03-19 11:17:29 +0000 |
---|---|---|
committer | Christian Schneider | 2007-03-19 11:17:29 +0000 |
commit | 7fb28fd960cd309a84fc74f390460503ab8c7810 (patch) | |
tree | 56d8c157a5e71f1e4c3370012d495e0c256c2a24 | |
parent | a282abd3b5b42b948e5ac7a8debdd59f381c7867 (diff) | |
download | itools-7fb28fd960cd309a84fc74f390460503ab8c7810.tar.gz itools-7fb28fd960cd309a84fc74f390460503ab8c7810.tar.bz2 itools-7fb28fd960cd309a84fc74f390460503ab8c7810.zip |
Prepend XML header for charset detection in PHP5
-rw-r--r-- | xml.class | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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)); |