loadHTML( $this->add_charset( $html_string, $charset ), ( \LIBXML_HTML_NOIMPLIED | \LIBXML_HTML_NODEFDTD ) ); \libxml_clear_errors(); return $dom; } /** * Add charset to the node html * * @param string $html_string The node html to add charset to. * @param string|null $charset The charset to add to the node html. * * @return string The node html with charset */ public function add_charset( string $html_string, ?string $charset ): string { if ( \is_null( $charset ) ) { return $html_string; } return \sprintf( '
%s', $charset, $html_string ); } }