Jump to content

Recommended Posts

Not sure if i'm doing this wrong or if i'm just using the wrong function. I have a very simple guestbook setup for our wedding site. It accepts plain text entries via a textarea field and retains them in a MySQL database. When i echo those back to the web site i want to replace all the user entered carriage returns (\n etc) with <br /> tags before it's printed to the page. This is how i have it so far (not working at all)...

$message = str_replace('\n','<br />',$row['message']);

echo '<div>'.$message.'</div>';

1) why isn't that working?
2) are line breaks specific to the server they're submitted to or the browser they're submitted from? For example, if it's server specific and on a unix server i'm guessing "\n" is correct, but if it's client/browser specific then i'd have to escape "^m" for mac "\n" for unix, "\r\n" for windows etc. right?

Anyone up for bringing this down to my level? :)
Link to comment
https://forums.phpfreaks.com/topic/6600-replacing-n-with/
Share on other sites

[!--quoteo(post=361714:date=Apr 4 2006, 04:24 PM:name=cmgmyr)--][div class=\'quotetop\']QUOTE(cmgmyr @ Apr 4 2006, 04:24 PM) [snapback]361714[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Have you tried this yet:[code]$something = nl2br($something);[/code]
[/quote]

didn't even know about that one...duh...thanks, that should work perfectly.
Link to comment
https://forums.phpfreaks.com/topic/6600-replacing-n-with/#findComment-23967
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.