Breaking News
Home / Web / HTML / How to convert newline entered in TextArea to HTML line breaks in PHP?

How to convert newline entered in TextArea to HTML line breaks in PHP?

Snippet

The data entered into the textarea in a html form contains lines break as n , however when we have to save and display the same data back as html and maintain the formatting, these line feed n needs to be converted into html </br> elements.

The following snippet shows the same:

  1. $text_with_breaks=nl2br($_POST[‘text’]);
  2. echo $text_with_breaks;

nl2br() is a function which inserts a
automatically at the end of every line.

[pb_builder]

Check Also

Coolest Things in HTML5

HTML (hypertext markup language) is very used markup language for the building the web pages. …

Advertisment ad adsense adlogger