Jump to content

Insert text with line-breaks


son

Recommended Posts

Have a textarea on web page, which inserts data into text table field. How do you make it, so when I press enter few time while entering text in textarea it actually created a line-break? The best would be if I could somehow control what is a new paragraph and what only a line-break. Is this possible?Son

Link to comment
Share on other sites

The line breaks are put into the database automatically. They just aren't viewed when outputting because in HTML source line breaks aren't counted.When retrieving the data from the database just use the nl2br() function in PHP or an equivalent in another server-side language.Here's a simple example, with most of the code omitted, on how to use nl2br on information from the database:

while($row = mysql_fetch_array($query)) {  echo $nl2br($row['message']);}

Link to comment
Share on other sites

The line breaks are put into the database automatically. They just aren't viewed when outputting because in HTML source line breaks aren't counted.When retrieving the data from the database just use the nl2br() function in PHP or an equivalent in another server-side language.Here's a simple example, with most of the code omitted, on how to use nl2br on information from the database:
while($row = mysql_fetch_array($query)) {  echo $nl2br($row['message']);}

Ingolme,You are my hero! This is what am after. One more question: would it be additionally possible to run the whole thing through some sort of function, so when there are two <br />, then it will replace those with </p><p> or similar? If that was possible, what do I want more:-)Son
Link to comment
Share on other sites

The function you're looking for is str_replace()Here's how you could have found it on your own. The manual is located at http://www.php.net If you add a slash and a key word to that address, you'll usually get some information. So try http://www.php.net/strings This brings up all kinds of stuff about strings, including a list of string functions. If you look through the list, I'm sure the word "replace" would catch your attention.

Link to comment
Share on other sites

The function you're looking for is str_replace()Here's how you could have found it on your own. The manual is located at http://www.php.net If you add a slash and a key word to that address, you'll usually get some information. So try http://www.php.net/strings This brings up all kinds of stuff about strings, including a list of string functions. If you look through the list, I'm sure the word "replace" would catch your attention.
Great stuff!Cheers,Son
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...