I'm trying to use the php nl2br() function to convert \r\n characters into <br>
tags in an email. There seems to be some sort of conflict when I try to use it with mysqli_real_escape_string(). I can verify seperately that the mysqli_real_escape_string function() is giving the proper output, and that the nl2br() function is properly converting the appropriate characters to <br>
tags, but they won't work together. Why?!
I can confirm nl2br works:
$message= "This\r\nis\n\ra\nstring\r";
$message= nl2br($message);
echo($message);
output:
"This is a string"
I can confirm mysqli_real_escape_string() works:
//assume $_POST['message'] = "this is a string"
$message = mysqli_real_escape_string($connection, $_POST['message']);
echo($message);
output:
This\r\nis\n\ra\nstring\r
When I use them together:
$message = nl2br(mysqli_real_escape_string($connection, $_POST['message']));
Output:
This\r\nis\r\na\r\nstring