NL2BR() PHP problem help please?
So on my website you are able to send messages. I use the nl2br() function so if someone presses enter, t开发者_高级运维heir text will have linebreaks. I realized though, if the person typing the text doesn't press enter and is instead wrapped by the textarea, the text is still broken. How can I avoid this? (How can I avoid linebreaks if the user doesn't press enter)
You can use the CSS style overflow: auto
on the textarea so that the textarea will render with a scrollbar if the text exceeds the width of the textarea.
#textareaId {
overflow: auto;
}
Set up your textarea like this:
<textarea style="white-space: nowrap; overflow: auto;">
</textarea>
Browser will no longer display automatic wraps, and will add scrollbars when user types past the right edge.
I found the answer:
I had wrap="hard" so when I changed it to wrap="soft" the user had to press enter to add linebreaks. Thanks for everyone's help.
The linebreaks caused by wrapping in the textarea are only displayed in the browser and will not be submitted with the form. If you don't want them to be converted to <br />
, that's fine, because they won't. (Not sure I understand your question.)
精彩评论