Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix utf-8 encoding problem #19

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixes UTF-8 encoding problem.
  • Loading branch information
shtse8 authored Feb 27, 2017
commit 02d7a6fa78dd6253e538426a0132dd4913a4a994
9 changes: 7 additions & 2 deletions src/HtmlPage.php
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ public function __construct($content = '', $url = '', $charset = 'UTF-8')
$disableEntities = libxml_disable_entity_loader(true);

$this->dom = new \DOMDocument('1.0', $charset);
$this->dom->loadHTML('<meta http-equiv="Content-Type" content="text/html;charset='.$charset.'">');
$this->dom->validateOnParse = true;


@@ -265,11 +266,15 @@ public function __toString()
*/
public function save($filename = '')
{
$html = $this->__toString();
if (function_exists('mb_convert_encoding') && in_array(strtolower($this->charset), array_map('strtolower', mb_list_encodings()))) {
$html = mb_convert_encoding($html, $this->charset, 'HTML-ENTITIES');
}
if ($filename != '') {
file_put_contents($filename, $this->__toString());
file_put_contents($filename, $html);
return;
} else {
return $this->__toString();
return $html;
}
}