Hacker News new | ask | show | jobs
by Firehed 4919 days ago
I've never once had the impression that nl2br did anything more than make whitespace significant in an HTML document. Even during my first days of using PHP... I don't think there's anything in the documentation or even trivially basic experimentation that could reasonably lead someone to believe that.

Plus the actual HTML-escaping tools (htmlspecialchars, htmlentities) do not make whitespace significant.

Though these days, you might arguably be better off with "white-space: pre-line" in CSS instead.

1 comments

It does less than making HTML whitespace-significant. It's unsuitable for use on HTML markup, because newlines in <script>, inside tags, attributes, comments, etc. should not be changed.

It's only safe and reliable as a part of nl2br(htmlspecialchars()) combo, so a function that does both could have been a better idea.