I have an issue where the function mysqli_real_escape_string, which is necessary causes funky behavior with line breaks. For example, when I store a message that looks like this:
$message = mysqli_real_escape_string("This is line 1
This is line 2
This is line 3");
It stores it like this in the database:
This is line 1\r\nThis is line 2\r\n\r\nThis is line 3
That’s fine, but when I retrieve it, like this:
$message = nl2br($data_from_db_table['message']);
The output is:
This is line 1rnThis is line 2rnrnThis is line 3
I am aware that to have special characters escaped, they need to be in double quotes, like: “\r\n” but since it’s being done by the mysqli_real_escape_string function, I’m not sure the right way to get the output to display properly, which would be:
This is line 1
This is line 2
This is line 3
Any help would be appreciated. Thanks in advance!