PHP 8.0.0 Released!

Einführung

Die DOM Erweiterung ermöglicht es, mit PHP durch die DOM API auf XML-Dokumente zuzugreifen.

Hinweis:

Die DOM Extension verwendet die UTF-8 Kodierung. Es kann utf8_encode() und utf8_decode() verwendet werden, um mit Texten in der ISO-8859-1 Kodierung zu arbeiten, oder iconv für andere Zeichenkodierungen.

add a note add a note

User Contributed Notes 2 notes

up
3
captainjester at hotmail dot com
8 months ago
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.
?>
up
2
Anonymous
7 months ago
On some linux package managers, namely apt, this is called 'xml' for example as in:

sudo apt-get install -y php7.3-xml
To Top