summaryrefslogtreecommitdiff
path: root/classes/feedparser.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-07-11 15:40:09 +0400
committerAndrew Dolgov <[email protected]>2013-07-11 15:40:09 +0400
commit4f00f55ca2ecd2e5a75c2c4ef37ca0e1143a7ac7 (patch)
tree104e0da9d23441a05d9c478de9abe258e9c6b9bd /classes/feedparser.php
parentd272da912082102ac52c73094abd61d463c25385 (diff)
parser: add charset recoding hack for systems where libxml is build without support for iconv (handles libxml error 32)
Diffstat (limited to 'classes/feedparser.php')
-rw-r--r--classes/feedparser.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/classes/feedparser.php b/classes/feedparser.php
index eb8606de9..53f6c52a9 100644
--- a/classes/feedparser.php
+++ b/classes/feedparser.php
@@ -20,6 +20,24 @@ class FeedParser {
$error = libxml_get_last_error();
+ // libxml compiled without iconv?
+ if ($error && $error->code == 32) {
+ if (preg_match('/^(<\\?xml .*?)encoding="(.+?)"(.*?\\?>)/', $data, $matches) === 1) {
+ libxml_clear_errors();
+
+ $enc = $matches[2];
+
+ $data = iconv($enc, 'UTF-8//IGNORE', $data);
+ $data = preg_replace('/^<\\?xml .*?\\?>/', $matches[1] . $matches[3] , $data);
+
+ $this->doc = new DOMDocument();
+ $this->doc->loadXML($data);
+
+ $error = libxml_get_last_error();
+ }
+ }
+
+ // some terrible invalid unicode entity?
if ($error && $error->code == 9) {
libxml_clear_errors();