Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

detecting new lines in textarea's using php

Posted on 2007-10-02
3
Medium Priority
?
840 Views
Last Modified: 2013-12-13
I'm sure this has been asked before but I haven't been able to find a solution.  Basically, a user fills out a textarea and they can enter breaks by pressing the Enter key.  How do I use str_replace() to detect the newline characters and replace them with a <br/> so that when it goes into and gets pulled out of the db it will be displayed correctly by the browser?
0
Comment
Question by:jpve
3 Comments
 
LVL 1

Accepted Solution

by:
JimQode earned 200 total points
ID: 19998333
nl2br() function does that.

you could also use str_replace("\n","<br>",$string)
0
 
LVL 3

Assisted Solution

by:BioI
BioI earned 200 total points
ID: 19998354
Hi,
I am usually using this function to change new lines to <br />: nl2br (more information on http://be.php.net/nl2br).

$stringwithbreaks = nl2br($textareastring);

regards,
bioi
0
 

Author Comment

by:jpve
ID: 19998653
Thanks a ton guys.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question