Skip to content

\Dom\HTMLDocument have null textContent, unlike \DOMDocument #17595

@momala454

Description

@momala454

Description

The following code:

<?php
$html = 'abc&lt;def<br>g';

$dom = \Dom\HTMLDocument::createFromString($html, options: LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED);
var_dump($dom->textContent);

$dom = new \DOMDocument(encoding: 'UTF-8');
$dom->loadHTML($html, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED);
var_dump($dom->textContent);

https://3v4l.org/t9WVN

Resulted in this output:

NULL
string(8) "abc<defg"

But I expected this output instead:

string(8) "abc<defg"
string(8) "abc<defg"

It may be not a bug, but in this case, how to simply get the same result ?

PHP Version

8.4.3

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions