Reputation: 2721
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?
Upvotes: 5
Views: 4794
Reputation: 164731
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
Upvotes: 2
Reputation: 117314
nodeValue returns only the text-data (if used on element-nodes). Retrieve the contents using saveXML()
$node->ownerDocument->saveXML($node);
Upvotes: 9
Reputation: 10667
Assuming you are using MySQL (since you don't say) make sure you use the function mysql_real_escape_string
. Dr.Molle's answer might provide further insight.
http://php.net/manual/en/function.mysql-real-escape-string.php
Upvotes: -1