I have a form where users can enter anything, for instance, suppose a user entered:
Hello World!
This is a new line.
This was written after two new lines.
The data that user submits using the form is inserted in DB:
$data = mysqli_real_escape_string($dbc, $_POST['text']);
$sql = "INSERT INTO data (Data) VALUES ('$data')";
$exec = mysqli_query($dbc, $sql);
Now it gets stored in database but when I fetch the text from the DB to show to the user, it displays:
Hello World! This is a new line. This was written after two new lines.
As you can see, the new lines are ignored. I also want to show line breaks.
I tried:
$data = mysqli_real_escape_string($dbc, str_replace('\n', '<br>', $_POST['text']));
but that doesn't work either. How can I show line breaks when displaying data from mysql?