Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadHTML drops first TextNode of HTML fragment string #208

Open
biziclop opened this issue Jun 8, 2021 · 1 comment
Open

loadHTML drops first TextNode of HTML fragment string #208

biziclop opened this issue Jun 8, 2021 · 1 comment

Comments

@biziclop
Copy link

biziclop commented Jun 8, 2021

Hi, thanks for the great project. I'm experimenting with parsing html strings. While I probably should use loadHTMLFragment() instead of loadHTML(), but I think this is still a bug.
If I try to loadHTML() a string which does not start with a tag but just with plain text, the first text segment is silently ignored.
In the example below, the starting text Aaa disappears from the regenerated HTML string:

require 'vendor/autoload.php';
$html5 = new Masterminds\HTML5();
$html = 'Aaa<br>Bbb<b>Ccc</b>Ddd';
$dom = $html5->loadHTML( $html );

echo $html5->saveHTML( $dom );
/* Result:
<!DOCTYPE html>
<html><br>Bbb<b>Ccc</b>Ddd</html>
*/

echo $dom->saveXML( $dom );
/* Result:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><br/>Bbb<b>Ccc</b>Ddd</html>
*/

@alecpl
Copy link
Contributor

alecpl commented Jul 9, 2021

Duplicate of #166.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants