note 124859 added to intro.dom

From: Date: Fri, 27 Mar 2020 12:59:36 +0000
Subject: note 124859 added to intro.dom
Groups: php.notes 
Request: Send a blank email to php-notes+get-214381@lists.php.net to get a copy of this message
Be careful when using this for partial HTML. This will only take complete HTML documents with at least an HTML element and a BODY element. If you are working on partial HTML and you fill in the missing elements around it and don't specify in META elements the character encoding then it will be treated as ISO-8859-1 and will mangle UTF-8 strings. Example: <?php $body = getHtmlBody(); $doc = new DOMDocument(); $doc->loadHtml("<html><body>".$body."</body></html>"); // $doc will treat your HTML ISO-8859-1. // this is correct but may not be what you want if your source is UTF-8 ?> <?php $body = getHtmlBody(); $doc = new DOMDocument(); $doc->loadHtml("<html><head><meta charset=\"UTF-8\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>".$body."</body></html>"); // $doc will treat your HTML correctly as UTF-8. ?> ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 198.84.240.230) ---- Manual Page -- http://php.net/manual/en/intro.dom.php Edit -- https://master.php.net/note/edit/124859 Del: integrated -- https://master.php.net/note/delete/124859/integrated Del: useless -- https://master.php.net/note/delete/124859/useless Del: bad code -- https://master.php.net/note/delete/124859/bad+code Del: spam -- https://master.php.net/note/delete/124859/spam Del: non-english -- https://master.php.net/note/delete/124859/non-english Del: in docs -- https://master.php.net/note/delete/124859/in+docs Del: other reasons-- https://master.php.net/note/delete/124859 Reject -- https://master.php.net/note/reject/124859 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214381) next »