Sign in to follow this  

[web] [PHP/HTML] help in processing textarea

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys.

I would like to print what I input in a <textarea>. My problem is, it doesn't print newlines.

e.g. I input:
"print
the
newlines
please"

It outputs: "print the newlines please"

I stored the input in $message and tried
$message = str_replace('\n', '<br />', $message) //doesn't work
echo $message

Anyone, help me in this please. Thanks!:)

Share this post


Link to post
Share on other sites
nl2br() will work. The problem with your original code is that you are using single quotes around the \n in str_replace(). \n only matches a newline in a double quoted string, e.g "\n". In single quotes, it matches a literal backslash + letter n.

Share this post


Link to post
Share on other sites

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this