johnhenry Posted February 5, 2015 Share Posted February 5, 2015 (edited) I want to email a post data message and I find that if, when writing the message in a text area and the enter key is pressed, the message has '\r\n' in it. When emailed the '\r\n is shown and there is no new line. I want to replace the '\r\n' with '<br>' and so I used the following script... $message = str_replace("\r\n","<br>",$message); This does not do a replace. The message stays the same. Can anyone tell me why this doesn't work please? Edited February 5, 2015 by johnhenry Quote Link to comment Share on other sites More sharing options...
scootstah Posted February 5, 2015 Share Posted February 5, 2015 Can you post the relevant code please? nl2br might be what you're looking for. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 5, 2015 Share Posted February 5, 2015 If you are seeing \r\n then something in your code is applying slashes to escaped characters (most likely from the use of addslashes). However there is no need to replace \r\n with a html break tag yourself. PHP can do this for you check out the nl2br function Quote Link to comment Share on other sites More sharing options...
Barand Posted February 5, 2015 Share Posted February 5, 2015 "\r\n" is 2 characters (CR LF) '\r\n' is 4 characters (note the single quotes) If you can see \r\n in the string then it's not a CRLF pair and nl2br() won't work, so try your str_replace with single quotes instead of double 1 Quote Link to comment Share on other sites More sharing options...
johnhenry Posted February 5, 2015 Author Share Posted February 5, 2015 Thanks Guru and Moderator. I have seen the light. I was using $value = mysql_real_escape_string($value) and $value = strip_tags($value) before the str_replace() function. Without them it works as expected, although the nl2br suggestion seems like a better way to go. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.