i use dom in php to retrieve a div's content by $node->nodeValue
. This div has many <br/>
tags in its content, but after i store it in the database and output it in the browser, all the <br/>
tags are changed to the whitespace. I want to keep the <br/>
tags, how do i achieve that?
DOMDocument::loadHTMLThe 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.
nodeValue returns only the text-data (if used on element-nodes). Retrieve the contents using saveXML()
$node->ownerDocument->saveXML($node);
DOMNode::nodeValue
will only return the text content.
As <br />
is a child element, it won't be returned.
Your best bet is to
$node
DOMDocument::saveHTML()
Something like this - http://www.php.net/manual/en/book.dom.php#89718
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With