Strange PHP behavior in nl2br function

I was reorganizing my small web application. all night long. Today, when I started testing, the first error I discovered was a problem with the PHP PHP function nl2br().

On my localhost, I have PHP version 5.2.9 , and, as I can see on the PHP site from version 4.0.5, it is nl2br() compatible with XHTML.

Then I absolutely do not understand why my nl2br()return <br>without the second argument is set to false instead <br />.

Here is my method where I found this error:

public function eliminateTags($msg) {
    $setBrakes = nl2br($msg);
    $decodeHTML = htmlspecialchars_decode($setBrakes);

    # Check PHP version
    if((int)version_compare(PHP_VERSION, '4.0.5') == 1) {
        $withoutTags = strip_tags($decodeHTML, '<br />');
    } else {
        $withoutTags = strip_tags($decodeHTML, '<br>');
    }

    return $withoutTags;
}
+3
source share
1 answer

, , . , HTML , , .

, HTML?

public function eliminateTags($msg) {
    $decodeHTML = htmlspecialchars_decode($msg);
    $withoutTags = strip_tags($decodeHTML);
    $setBreaks = nl2br($withoutTags);

    return $setBreaks;
}

Edit:

-, strip_tags() . PHP, , <br>, <br />. PHP, <br />, , , <p></p>, .

, , , PHP - strip_tags() , .

+4

Source: https://habr.com/ru/post/1753034/


All Articles