Skip to content

Commit b400ac6

Browse files
committed
Added the option to enforce the encoding
1 parent dd21b26 commit b400ac6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ protected function detectCharset()
594594
$encode->from($this->defaultCharset);
595595
$encode->to($this->defaultCharset);
596596

597+
if ( ! is_null($this->options->enforceEncoding))
598+
{
599+
// they want to enforce the given encoding
600+
$encode->from($this->options->enforceEncoding);
601+
$encode->to($this->options->enforceEncoding);
602+
return false;
603+
}
604+
597605
$meta = $this->root->find('meta[http-equiv=Content-Type]', 0);
598606
if (is_null($meta))
599607
{

src/PHPHtmlParser/Options.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Options {
1111
protected $defaults = [
1212
'whitespaceTextNode' => true,
1313
'strict' => false,
14+
'enforceEncoding' => null,
1415
];
1516

1617
/**

0 commit comments

Comments
 (0)