note 112830 modified in domdocument.savehtmlfile by peehaa
| From: | peehaa@php.net | Date: | Sat, 27 Jul 2013 16:23:57 +0000 |
| Subject: | note 112830 modified in domdocument.savehtmlfile by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195792@lists.php.net to get a copy of this message | ||
saveHTMLFile() always saves the file in UTF-8. Even if the DOMDocument->encoding explicitly
prescribe different from UTF-8 encoding. All "non-Latin" characters will be converted to
HTML-entities. Tested in PHP 5.2.9-2 and PHP 5.2.17. Example:
<?php
$document=new domDocument('1.0', 'WINDOWS-1251');
$document->loadHTML('<html><head><title>Russian
language</title></head><body>Ð ÑÑÑкий
ÑзÑк</body></html>');
$document->formatOutput=true;
$document->encoding='WINDOWS-1251';
echo "ÐапиÑано байÑ. Recorded bytes:
".$document->saveHTMLFile('html.html');
?>
Method recorded file in UTF-8 encoding. The contents of the file html.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Russian language</title>
</head>
<body>Ðóññêèé
ÿçûê</body>
</html>
--was--
saveHTMLFile() вÑегда ÑоÑ
ÑанÑÐµÑ Ñайл в
кодиÑовке UTF-8. Ðаже еÑли в
DOMDocument->encoding Ñвно пÑопиÑаÑÑ
оÑлиÑнÑÑ Ð¾Ñ UTF-8 кодиÑовкÑ. ÐÑи
ÑÑом вÑе "нелаÑинÑкие"
ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ Ð±ÑдÑÑ
пÑеобÑÐ°Ð·Ð¾Ð²Ð°Ð½Ñ Ð²
ÑооÑвеÑÑÑвÑÑÑие им
HTML-ÑÑÑноÑÑи (HTML-entities). ÐÑовеÑено в PHP
5.2.9-2 и PHP 5.2.17. ÐÑимеÑ:
saveHTMLFile() always saves the file in UTF-8. Even if the DOMDocument->encoding explicitly
prescribe different from UTF-8 encoding. All "non-Latin" characters will be converted to
HTML-entities. Tested in PHP 5.2.9-2 and PHP 5.2.17. Example:
<?php
$document=new domDocument('1.0', 'WINDOWS-1251');
$document->loadHTML('<html><head><title>Russian
language</title></head><body>Ð ÑÑÑкий
ÑзÑк</body></html>');
$document->formatOutput=true;
$document->encoding='WINDOWS-1251';
echo "ÐапиÑано байÑ. Recorded bytes:
".$document->saveHTMLFile('html.html');
?>
saveHTMLFile() запиÑала Ñайл html.html в
кодиÑовке UTF-8. СодеÑжимое
Ñайла html.html.
Method recorded file in UTF-8 encoding. The contents of the file html.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Russian language</title>
</head>
<body>Ðóññêèé
ÿçûê</body>
</html>
http://php.net/manual/en/domdocument.savehtmlfile.php