How to preserve line breaks from a text area with PHP?

Spread the love

Sometimes, we want to preserve line breaks from a text area with PHP.

In this article, we’ll look at how to preserve line breaks from a text area with PHP.

How to preserve line breaks from a text area with PHP?

To preserve line breaks from a text area with PHP, we can use the nl2br function.

For instance, we write

echo nl2br("This\r\nis\n\ra\nstring\r");

to return a string with '\r\n' and '\r' replaced with '<br />'.

Conclusion

To preserve line breaks from a text area with PHP, we can use the nl2br function.

Leave a Reply

Your email address will not be published. Required fields are marked *