note 118509 added to class.domdocument

From: Date: Thu, 17 Dec 2015 07:34:04 +0000
Subject: note 118509 added to class.domdocument
Groups: php.notes 
Request: Send a blank email to php-notes+get-204468@lists.php.net to get a copy of this message
For those landing here and checking for encoding issue with utf-8 characteres, it's pretty easy to correct it, without adding any additional output tag to your html. We'll be utilizing: mb_convert_encoding Thanks to the user who shared: SmartDOMDocument in previous comments, I got the idea of solving it. However I truly wish that he shared the method instead of giving a link. Anyway coming back to the solution, you can simply use: <?php // checks if the content we're receiving isn't empty, to avoid the warning if ( empty( $content ) ) { return false; } // converts all special characters to utf-8 $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'); // creating new document $doc = new DOMDocument('1.0', 'utf-8'); //turning off some errors libxml_use_internal_errors(true); // it loads the content without adding enclosing html/body tags and also the doctype declaration $doc->LoadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); // do whatever you want to do with this code now ?> I hope it solves the issue for someone! If you need my help or service to fix your code, you can reach me on nabtron.com or contact me at the email mentioned with this comment. ---- Server IP: 72.52.91.14 Probable Submitter: 39.33.106.139 ---- Manual Page -- http://php.net/manual/en/class.domdocument.php Edit -- https://master.php.net/note/edit/118509 Del: integrated -- https://master.php.net/note/delete/118509/integrated Del: useless -- https://master.php.net/note/delete/118509/useless Del: bad code -- https://master.php.net/note/delete/118509/bad+code Del: spam -- https://master.php.net/note/delete/118509/spam Del: non-english -- https://master.php.net/note/delete/118509/non-english Del: in docs -- https://master.php.net/note/delete/118509/in+docs Del: other reasons-- https://master.php.net/note/delete/118509 Reject -- https://master.php.net/note/reject/118509 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204468) next »