DOMDocument::loadHTML

(PHP 5, PHP 7, PHP 8)

DOMDocument::loadHTML Load HTML from a string

Beschreibung

public DOMDocument::loadHTML(string $source, int $options = 0): DOMDocument|bool

The function parses the HTML contained in the string source. Unlike loading XML, HTML does not have to be well-formed to load. This function may also be called statically to load and create a DOMDocument object. The static invocation may be used when no DOMDocument properties need to be set prior to loading.

Parameter-Liste

source

The HTML string.

options

Since Libxml 2.6.0, you may also use the options parameter to specify additional Libxml parameters.

Rückgabewerte

Gibt bei Erfolg true zurück. Bei einem Fehler wird false zurückgegeben. If called statically, returns a DOMDocumentBei einem Fehler wird false zurückgegeben..

Fehler/Exceptions

If an empty string is passed as the source, a warning will be generated. This warning is not generated by libxml and cannot be handled using libxml's error handling functions.

Vor PHP 8.0.0 konnte diese Methode statisch aufgerufen werden, gab dabei aber einen Fehler der Stufe E_DEPRECATED aus. Seit PHP 8.0.0 löst der statische Aufruf dieser Methode eine Error-Exception aus.

Auch wenn fehlerhaftes HTML erfolgreich laden sollte, kann diese Funktion dennoch Fehler der Stufe E_WARNING generieren, wenn sie auf falsches Markup stößt. Die Fehlerbehandlungsfunktionen von libxml können genutzt werden, um diese Fehler zu behandeln.

Beispiele

Beispiel #1 Creating a Document

<?php
$doc 
= new DOMDocument();
$doc->loadHTML("<html><body>Test<br></body></html>");
echo 
$doc->saveHTML();
?>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

How do you keep up with PHP and Database updates?

Hello everyone, PHP and database systems (MySQL, PostgreSQL, etc.) are evolving so quickly. Sometimes it feels hard to stay updated with new vers ...

Geschrieben von helen9k am 06.09.2025 10:35:52
Forum: Ankündigungen
Best Way to Handle Millions of Rows in MySQL – Indexing vs Partitioning?

Hi everyone, I’m working with a MySQL table that already has several million rows, and performance is starting to slow down (queries and joins ...

Geschrieben von helen9k am 06.09.2025 10:31:12
Forum: SQL / Datenbanken
Best Practices for Handling User Login and Session Security in PHP

Hi everyone, I’ve been working on a small PHP project with user login functionality, and I want to make sure I’m following good practices for ...

Geschrieben von helen9k am 06.09.2025 09:39:26
Forum: PHP Developer Forum
PHPMailer Umlaute Probleme

"Hey! Good start with PHPMailer. I also ran into encoding issues with special characters. Ensure your charset is set to "UTF-8". Might be a silly ...

Geschrieben von Varo78 am 05.09.2025 06:56:27
Forum: PHP Developer Forum