I'm using XPath to get div contenteditable's content and insert it in DB. But when I output the content there are no new lines.
$divs = $xpath->query('//div');
foreach($divs as $book) {
$text = nl2br($book->textContent);
}
What am I doing wrong? Thanks in advance :)
$book->textContent
strips all markup from the content [1], such as <div>
which are naturally inserted when you hit enter on an contenteditable
-Element. Therefore all this function returns is a concatenation of pure text.
I'm not sure what your goal is, but you might look into $your_DOMDocument->saveHTML($book)
. This will return the actual HTML of each $book
including the surrounding <div>
.
[1]: see the DOM Specifications