Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Converting Textarea Return Characters To <br />
paulmason411
post Dec 7 2007, 10:10 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 69
Joined: 18-November 06
Member No.: 33,593



Hi guys,

I have set up a form with a textarea. If I have text on multiple lines such as:

CODE
here is some content

here is some more content



then when I print it out as html it will be returned on one line like so:

CODE
here is some contenthere is some more content


When i look at the content in the database it looks just like the original way i entered it (contains the multiple lines).

Is there a function in php so that when i spit it out in html it retains the multiple line format?

Thanks in advance.
Go to the top of the page
 
+Quote Post
jlhaslip
post Dec 7 2007, 12:54 PM
Post #2


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,081
Joined: 24-July 05
From: Linix, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol



try this:
CODE
$value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value);
Go to the top of the page
 
+Quote Post
mahirharoon
post Dec 7 2007, 02:02 PM
Post #3


Advanced Member
*******

Group: Members
Posts: 102
Joined: 25-November 07
Member No.: 53,695



put \n at last of the line
Go to the top of the page
 
+Quote Post
paulmason411
post Dec 7 2007, 02:07 PM
Post #4


Member [Level 1]
****

Group: Members
Posts: 69
Joined: 18-November 06
Member No.: 33,593



jlhaslip you've done it again. Thanks!
Go to the top of the page
 
+Quote Post
ewcreators
post Dec 7 2007, 02:20 PM
Post #5


Member [Level 1]
****

Group: Members
Posts: 59
Joined: 28-August 07
Member No.: 48,983



QUOTE(paulmason411 @ Dec 7 2007, 10:07 AM) *
jlhaslip you've done it again. Thanks!

that may be sorta complex.
The easiest way is to use :
CODE
<?php
$line_break=nl2br($_POST['text']);
echo $line;
?>

nl2br() is a function which inserts a <br /> automatically at the end of every line.
Go to the top of the page
 
+Quote Post
jlhaslip
post Dec 7 2007, 03:24 PM
Post #6


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,081
Joined: 24-July 05
From: Linix, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol



CODE
$value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value);

I use that in a function that replaces all the bad stuff in Emails, Comments, $_POST arrays, etc.
Yes, probably a little overkill checking for the hex values. And you are correct, the nl2br() would likely do it.

I had not had my morning coffee yet when I replied... tongue.gif
Go to the top of the page
 
+Quote Post
iGuest
post Jun 22 2008, 03:00 AM
Post #7


Hail Caesar!
*********************

Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



character count
Converting Textarea Return Characters To


Guys teach me how to post the character count on php from the html textarea. I know how to do the wordcount but the character count is really my problem

Need help

-reply by abby
Go to the top of the page
 
+Quote Post
who?
post Jul 9 2008, 11:23 PM
Post #8


Newbie [Level 1]
*

Group: Members
Posts: 12
Joined: 10-April 06
Member No.: 21,606



QUOTE(FeedBacker @ Jun 22 2008, 04:00 AM) *
character count

Converting Textarea Return Characters To
Guys teach me how to post the character count on php from the html textarea. I know how to do the wordcount but the character count is really my problem

Need help

-reply by abby


I'm not sure if I understand your problem, but try using strlen($str), where $str is the textarea value.

This post has been edited by who?: Jul 9 2008, 11:23 PM
Go to the top of the page
 
+Quote Post
optiplex
post Jul 21 2008, 06:13 PM
Post #9


Newbie [Level 3]
***

Group: [HOSTED]
Posts: 40
Joined: 26-June 08
Member No.: 64,213



Oh thats really simple!

you can replace newlines using str_replace

like this

CODE
$your_string = str_replace(array(chr(10), chr(13)), "<br />", $your_string);


or you can use nl2br

CODE
$your_string = nl2br($your_string);


BUT if you are showing html code anyway, you can write it in a textarea

like : <textarea><? echo $your_string; ?></textarea>

or using the <PRE> tag, like this:
<PRE><? echo $your_string; ?></PRE>

But there are more options afcourse
Thats it!

- optiplex

This post has been edited by optiplex: Jul 21 2008, 06:16 PM
Go to the top of the page
 
+Quote Post
gogoily