public static function docPart($htmlPart, $encoding = 'utf-8', $docType = NULL) {
    if (!is_string($htmlPart))
      $htmlPart = self::export($htmlPart);
    
    if (mb_strpos(trim($htmlPart), '<!DOCTYPE') === 0) {
      $document = $htmlPart;
    } else {
      // DOMDocument setzt so oder so einen default, also können wir das auch explizit machen
      $docType = $docType ?: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';

      // ebenso das encoding ist utf8
      $document  = $docType."\n";
      
      if (mb_strpos(trim($htmlPart),'<html') === 0) {
        $document .= $htmlPart;
      } else {
        $document .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'"/></head><body>'.$htmlPart.'</body></html>';
      }
    }
    
    return self::doc($document);
  }
public static function docPart($htmlPart, $encoding = 'utf-8', $docType = NULL) {
    if (!is_string($htmlPart))
      $htmlPart = self::export($htmlPart);
    
    if (mb_strpos(trim($htmlPart), '<!DOCTYPE') === 0) {
      $document = $htmlPart;
    } else {
      // DOMDocument setzt so oder so einen default, also können wir das auch explizit machen
      $docType = $docType ?: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';

      // ebenso das encoding ist utf8
      $document  = $docType."\n";
      
      if (mb_strpos(trim($htmlPart),'<html') === 0) {
        $document .= $htmlPart;
      } else {
        $document .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'"/></head><body>'.$htmlPart.'</body></html>';
      }
    }
    
    return self::doc($document);
  }
public static function docPart ( $ htmlPart , $ encoding = 'utf-8' , $ docType = NULL ) { if ( ! is_string ( $ htmlPart ) ) $ htmlPart = self :: export ( $ htmlPart ) ; if ( mb_strpos ( trim ( $ htmlPart ) , '<!DOCTYPE' ) === 0 ) { $ document = $ htmlPart ; } else { // DOMDocument setzt so oder so einen default, also können wir das auch explizit machen $ docType = $ docType ? : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' ; // ebenso das encoding ist utf8 $ document = $ docType . "\n" ; if ( mb_strpos ( trim ( $ htmlPart ) , '<html' ) === 0 ) { $ document .= $ htmlPart ; } else { $ document .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset=' . $ encoding . '"/></head><body>' . $ htmlPart . '</body></html>' ; } } return self :: doc ( $ document ) ; }
Takes any HTML snippet and makes a correct DOMDocument out of it

nimmt als default
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
an
@param string $html ein HTML Schnipsel
@return DOMDocument
Takes any HTML snippet and makes a correct DOMDocument out of it