Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"ext-mbstring": "*",
"ext-libxml": "*",
"lib-libxml": ">=2.7.7",
"symfony/css-selector": "^3.1"
"symfony/css-selector": "^3.1",
"neitanod/forceutf8": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "4.6.*",
Expand Down
6 changes: 3 additions & 3 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use DOMWrap\Traits\CommonTrait;
use DOMWrap\Traits\TraversalTrait;
use DOMWrap\Traits\ManipulationTrait;
use ForceUTF8\Encoding as ForceUTF8;


/**
* Document Node
Expand Down Expand Up @@ -96,10 +98,8 @@ public function setHtml($html) {

if (mb_detect_encoding($html, mb_detect_order(), true) !== 'UTF-8') {
if (preg_match('@<meta.*?charset=["\']?([^\'"\s]+)@im', $html, $matches)) {
$charset = strtoupper($matches[1]);

$html = preg_replace('@(charset=["\']?)([^\'"\s]+)([^\'"]*[\'"]?)@im', '$1UTF-8$3', $html);
$html = mb_convert_encoding($html, 'UTF-8', $charset);
$html = ForceUTF8::fixUTF8($html);
} else {
$html = mb_convert_encoding($html, 'UTF-8', 'auto');
}
Expand Down