note 112830 modified in domdocument.savehtmlfile by peehaa

From: 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>&ETH;&oacute;&ntilde;&ntilde;&ecirc;&egrave;&eacute; &yuml;&ccedil;&ucirc;&ecirc;</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>&ETH;&oacute;&ntilde;&ntilde;&ecirc;&egrave;&eacute; &yuml;&ccedil;&ucirc;&ecirc;</body> </html> http://php.net/manual/en/domdocument.savehtmlfile.php

« previous php.notes (#195792) next »