1

I have this data in a database:

http://pastebin.com/wdgj3aTr

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);
    }
}
1
  • What does this have to do with MySQL Commented May 30, 2014 at 11:51

2 Answers 2

1
if(!function_exists("dropHtmlTags")) {
    function dropHtmlTags($string) {
        // remove html tags
        $string = strip_tags($string, ' \r\n\t'); 
        echo nl2br($string);
    }
}
Sign up to request clarification or add additional context in comments.

13 Comments

that still displays just one block of text
$string = "hi I am pra\nva"; $string = strip_tags($string, ' \r\n\t'); echo nl2br($string);
I have just tried that, its working ok but shows /> at the end of each line and line breaks in the wrong place
Have you tried with nl2br() method? Can you please put your code again!
if(!function_exists("dropHtmlTags")) { function dropHtmlTags($string) { // remove html tags $string = strip_tags($string, ' \r\n\t'); return nl2br($string); } } echo dropHtmlTags("Hi I am Pra\nva"); This one works perfectly, I checked just now.
|
1

Instead of stripping the \n (new line) replace it with <br />

Other possibility, don't strip the \n and wrap everything in <pre></pre>

1 Comment

do you have an example please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.