From a051d38df9094ccb6cac8e62587d08c477cd09df Mon Sep 17 00:00:00 2001 From: bastei Date: Fri, 6 Sep 2013 17:45:52 +0200 Subject: try detect encoding of documents in ArticleEnhancer and convert them --- utility/articleenhancer/articleenhancer.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'utility') diff --git a/utility/articleenhancer/articleenhancer.php b/utility/articleenhancer/articleenhancer.php index 76bb0fa9f..c9b61a135 100644 --- a/utility/articleenhancer/articleenhancer.php +++ b/utility/articleenhancer/articleenhancer.php @@ -60,8 +60,16 @@ abstract class ArticleEnhancer { if(preg_match($regex, $item->getUrl())) { $file = $this->fileFactory->getFile($item->getUrl(), $this->maximumTimeout); + + // convert encoding by detecting charset from header + $contentType = $file->headers['content-type']; + if( preg_match( '/(?<=charset=)[^;]*/', $contentType, $matches ) ) + $body = mb_convert_encoding($file->body, 'HTML-ENTITIES', $matches[0]); + else + $body = $file->body; + $dom = new \DOMDocument(); - @$dom->loadHTML($file->body); + @$dom->loadHTML($body); $xpath = new \DOMXpath($dom); $xpathResult = $xpath->evaluate($search); -- cgit v1.2.3