Reputation:
I have this data in a database:
I am able to show plain text using this PHP function:
if(!function_exists("dropHtmlTags")) {
function dropHtmlTags($string) {
// remove html tags
$string = strip_tags($string, ' \r\n\t');
return $string;
}
}
but i want to keep the line breaks when displaying, how can i do this?
UPDATED CODE
if(!function_exists("dropHtmlTags")) {
function dropHtmlTags($string) {
// remove html tags
$string = strip_tags($string, ' \r\n\t');
return nl2br($string);
}
}
Upvotes: 1
Views: 91
Reputation: 3986
if(!function_exists("dropHtmlTags")) {
function dropHtmlTags($string) {
// remove html tags
$string = strip_tags($string, ' \r\n\t');
echo nl2br($string);
}
}
Upvotes: 1
Reputation: 1385
Instead of stripping the \n
(new line) replace it with <br />
Other possibility, don't strip the \n
and wrap everything in <pre></pre>
Upvotes: 1