php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69097 DOMNode->textContent completely ignores <br> newlines.
Submitted: 2015-02-21 11:09 UTC Modified: 2015-02-21 11:46 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: divinity76 at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.6.6 OS: insignificant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: divinity76 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-02-21 11:09 UTC] divinity76 at gmail dot com
Description:
------------
DOMNode->textContent created with DOMDocument->loadHTML completely ignores <br> newlines.

i guess Bug #32581
could be related, but this is for PHP5/7, that's for PHP4

Test script:
---------------
<?php
$domd=new DOMDocument();
$domd->loadHTML("<pre>line1<br/>line2\nline3</pre>");
var_dump($domd->textContent);

Expected result:
----------------
string(17) "line1
line2
line3" //<<expected result when newlines are 1 byte long

Actual result:
--------------
string(16) "line1line2
line3"//<<actual result when newlines are 1 byte long

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-21 11:15 UTC] divinity76 at gmail dot com
it is bothering me right now, does anyone know a workaround?
 [2015-02-21 11:34 UTC] divinity76 at gmail dot com
$domd->loadHTML(preg_replace('/<br\\s*?\/??>/i', PHP_EOL, $html));

seems to work
 [2015-02-21 11:46 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-02-21 11:46 UTC] requinix@php.net
Keeping in mind that it is defined by the DOM standards,
http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent

textContent does not involve interpreting the meaning of elements. It is strictly just the text content of nodes, and <br>s have no content.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 14:01:29 2024 UTC